Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Seekers of Perl Wisdom

( #479=superdoc: print w/replies, xml ) Need Help??

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask. Post a new question!

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

User Questions
url get with string
2 direct replies — Read more / Contribute
by bigup401
on Mar 23, 2017 at 04:34

    why if i post like this it doesn't work

    $name = 'john'; my $req = HTTP::Request->new(GET => '$nam +e'); $req->content_type('application/json');

    but it works when no $name string in url

    my $req = HTTP::Request->new(GET => ' +'); $req->content_type('application/json');
Unable to connect to HTTPS servers
2 direct replies — Read more / Contribute
by prathap keerthipati
on Mar 23, 2017 at 02:57

    Hi Perl Monks,

    I have a perlscript which is connecting to urls and downloading the contents of that.The script we are running in unix environment connecting through the proxy server.For http urls it is running fine, but when i gave https url its throwing error like "500 cannot connect to url". I am using WWW::Mechanize module and LWP 6.04v in the script. Can anybody suggest the solution for this? and what are the possible ways to get 500 connection issue?

User interface using drag and droop
3 direct replies — Read more / Contribute
by Anonymous Monk
on Mar 22, 2017 at 21:10

    How to create a box user interface, so when I drag and drop into the tool it will tell me the file meets my specifications or not. Thanks.

CPAN install module error
2 direct replies — Read more / Contribute
by staszeko
on Mar 22, 2017 at 20:47

    I have a problem downloading Perl module 'Log::Log4Perl' using CPAN on Linux CentOS.

    When I execute command
    # cpan -i Perl::Log4Perl

    I get error
    Can't locate object method "data" via package "CPAN::Modulelist" (perhaps you forgot to load "CPAN::Modulelist"?)

    I loaded newer indicies using command
    cpan> reload index

    then loaded again
    cpan> reload cpan

    then removed entire directory '.cpan' including file '', but this did not solve the problem.

    I would much appreciate any pointers that could lead me to a successful resolution.

    cpan script version 1.03 version 1.7602

    Linux 2.6.18-308.13.1.el5PAE #1 SMP Thu Jul 26 06:08:24 EDT 2012 i686 i386 GNU/Linux

Not a HASH reference
4 direct replies — Read more / Contribute
by pdahal
on Mar 22, 2017 at 12:06
    I am getting following error in perl. "Not a HASH reference at line 31". the code.Below is the code through where I am getting this error. How can I correct it? The last line of the code is line 32
    my $src = dir("C:/Perl/pubmed/Prasuna/DM/Database/Drugbank/Split"); #Check files in folder my @txt_files = $src->children; for my $txt_file ( @txt_files ) { my $in = $txt_file->openr; my $parser = new XML::Simple; my $tree = $parser->XMLin($in); $alldrug = $tree->{drug}; #print pp($alldrug); @allkeys = keys % $alldrug;
html parsing
6 direct replies — Read more / Contribute
by bigup401
on Mar 22, 2017 at 10:23

    if i send get request. any idea how i can parse response to print only like <title>Hello</title> prints Hello only

    my $req = HTTP::Request->new(GET => ''); $req->content_type('application/json'); my $res = $ua->request($req);
Mail - 32bit vs 64bit
3 direct replies — Read more / Contribute
by krausr
on Mar 22, 2017 at 08:57

    I have a script that emails me details from a file. The script works fine in a 32-bit version of Activeperl, but does not run using a 64-bit version. It seems to crap out on this line:

    $smtp->mail($email_from); # sender's address
  • Why would that ever be a case?
  • How can I fix this to work on either version?
  • use Net::SMTP; use Win32::EventLog; $summary = ''; $extra = ''; $begin_summary = 0; $data_file = "C:/Logs/myfile.log"; open(IN, $data_file) || die("Could not open file!"); @raw_data = <IN>; close(IN); for my $row (@raw_data) { if ( $row =~ /\s+Total\s+Copied\s+Skipped\s+Mismatch\s+FAILED\s+Ex +tras\s+/ ) { $begin_summary = 1; } if ( $begin_summary ) { $summary .= $row; } if ($row =~ /\s+Ended \: /) { #print "Exiting loop\n"; last; } } write_event(900, EVENTLOG_INFORMATION_TYPE, $summary); send_email("My Big Fat Notification - " . $ENV{COMPUTERNAME}, "$extra\ +n$summary"); sub send_email() { my ($subject, $body) = @_; my $email_from = ''; my $email_to = (''); my $smtp = Net::SMTP->new(''); # Connect to a +n SMTP server $smtp->mail($email_from); # sender's address $smtp->to($email_to); # Recipient's address $smtp->data(); # Start the mail # Send the header. $smtp->datasend("To: $email_to\n"); $smtp->datasend("From: $email_from\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("\n"); MORE CODE AFTER THIS...
Accessing the hash name in perl
5 direct replies — Read more / Contribute
by Sonali
on Mar 22, 2017 at 08:11

    Hello Perl monks,

    I am a Perl newbie

    I am try to get the name of the hash which is in another Perl file, and then access the hash elements, but when I run my program I am getting these errors

    Use of uninitialized value $line in pattern match (m//) at line 17.

    Use of uninitialized value $typ_s in string at line 20.

    My code goes like this

    package hash; use strict; use warnings; $test = { 'hash1' => { 'paramA' => '00' , 'paramB' => 'FF' , }, 'hash2' => { 'paramA' => '01' , 'paramB' => '02' , }, 'hash3' => { 'paramA' => '00' , 'paramB' => '03' , }, };

    This the Perl file which contains the hash that needs to be extracted

    This is the Perl script I have written to extract the hash

    #!/usr/local/bin/perl use strict; use warnings; Generate(); sub Generate { Process_File(''); } sub Process_File { my $filename = shift; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my $line; $line =~ m/\'hash1\'/; my $typ_s = $line->{paramA}; my $paramB = $line->{paramB}; print "$typ_s"; }

    Help me!

How to calculate the column and print it in pie chart format using perl?
3 direct replies — Read more / Contribute
by finddata
on Mar 22, 2017 at 00:37
    I have the following mysql table which obtained by following query(sel +ect * from tables); <code> | time | queue_name | description + | priority | jobs_pending | jobs_running | | 1490155563 | adice_long | ADICE Low-Priority/Long Runtime Job Q +ueue | 5 | 6 | 3 + + | 1490155563 | adice | ADICE +Low-Priority/Long Runtime Job Queue | 8 | 9 + | 3 + + + + + + | | 1490155563 | incisive | ADICE-Incisive Co-Simulation Queue + | 7 | 0 | | 1490155563 | vcs | ADICE High-Priority/Short Runtime Job + Queue | 10 | 0 | | +
    My query is i want to convert the above table into pie chart format . i should built two piechart one is for jobs pending and jobs running by matching it with queue name. If the queue name is available twice in the column we should calculate those two rows of jobs pending and jobs running and make them into single. code which i had tried are as follows:
    print "var data_running=[[\"Adice \($TABLE_DATA{1}{'ENTRY'}\)\",$TABLE +_DATA{5}{'ENTRY'}],\ [\"Incisive \($TABLE_DATA{1}{'ENTRY'}\)\",$TABLE_ +DATA{5}{'ENTRY'}],\ [\"Vcs \($TABLE_DATA{1}{'ENTRY'}\)\",$TABLE_DATA{ +5}{'ENTRY'}], \n"; print "var data_pending=[[\"Adice \($TABLE_DATA{1}{'ENT +RY'}\)\",$TABLE_DATA{4}{'ENTRY'}],\ [\"Incisive \($TABLE_DATA{1}{'ENTRY'}\)\",$TABLE_ +DATA{4}{'ENTRY'}],\ [\"Vcs \($TABLE_DATA{1}{'ENTRY'}\)\",$TABLE_DATA{ +4}{'ENTRY'}],\n"; +
    print " \n + pieChart(\"placeholder39\",data_running,{title:\"<b><center>Jobs Run +ning</center></b>\"});\n"; print " \n pieChart(\"placeholder41\",data_pending,{title:\"<b>< +center>Jobs Pending</center></b>\"});\n";
    But am not sure am in right way to do it. |
How to read the input directory from command line arguments using perl?
3 direct replies — Read more / Contribute
by finddata
on Mar 21, 2017 at 23:56
    I have the project.txt files at following directory (/home/data/check_ +data). project.txt contins following contents: <code> PROJECT { NAME:DCMS_DEMO BLOCKS:test,de_top,new_block2 DENY_USERS: WELCOME: REVISION_LOCATION:../setup/projects/DCMS_DEMO/project_space CHECKLISTS:Synthesis_L2_checklist,Block_Physical_design_checklist,ICC_ +L2_Checklist,Overall_DV,Formality_DCT_Vs_ICC,Fullchip_Physical_design +_checklist,Formality_RTL_Vs_DCT,synthesis,Timing_analysis_checklist,c +hecklist_tmp,Power_analysis_checklist,Block_DV,DFT,ICC_Top_level_Chec +klist,test_copy_checklist,ICC_DPMHV_Checklist,CAD_checklist,FrontEnd_ +Design_Checklist DESCRIPTION:Demonstration project OWNER:sanandak ALLOWED_UNIX_GROUPS: }
    Now i like to read the directory whereever the line starts with (REVISION_LOCATION:) from the project.txt files.And those directories should be consider as my input directory from the command line arguments.How can i do it. code which i had tried are as follows:
    #! /usr/bin/env perl use strict; use warnings; use Getopt::Long qw( GetOptions ); GetOptions( 'root=s' => \my $input_dir, 'outdir=s' => \my $output_dir, 'file=s' => \my $mapfile, ) In the above i called the directory straightly from the location but m +y question is first i should read the project.txt file from one locat +ion and from that project.txt file i should read the directory(i.e t +he line starts with REVISION_LOCATION).How can i script it using perl +?

Add your question
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    erix self-flagellates with the cluebat
    [erix]: indeed had to be( time make check-world ) > test_run2.output 2>&1
    [erix]: probably misremembered because of 2>&1 |
    [erix]: oh nice, can do |& nowadays. Learned something new after all
    LanX flagelates erix with a signed markov chain

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (10)
    As of 2017-03-23 08:55 GMT
    Find Nodes?
      Voting Booth?
      Should Pluto Get Its Planethood Back?

      Results (285 votes). Check out past polls.