Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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
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 tocsvfd.pl 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 => 'https://www.google.com'); $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 = 'fromster@frobot.com'; my $email_to = ('toster@frobot.com'); my $smtp = Net::SMTP->new('smtpserver.frobot.com'); # 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
4 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 test.pm line 17.

    Use of uninitialized value $typ_s in string at test.pm 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('hash.pm'); } 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 +?
CPAN::Mini on a diet
2 direct replies — Read more / Contribute
by glasswalk3r
on Mar 21, 2017 at 19:14

    Hello follow monks,

    Are you aware of any technique to reduce the size of a CPAN::Mini repository?

    I was checking my local mirror here and it is around 4.9Gb on a OpenBSD 6 box with FFS.

    Taking a look at my ID under authors directory, I see that there are tarballs over there that are not even listed on my PAUSE account anymore (might be some issue regarding mirror synchronization). Anyway, I guess that for my purposes I could use only the latest available distribution for everybody.

    A quick check on CPAN::Mini and minicpan documentation doesn't show anything that would help with that.

    Is there any trick to take care of it?

    Thanks!

    UPDATED

    I tried this:

    Still pending to validate if it didn't break anything...

    Anyway, I was able to reduce it to 3.0Gb from the initial 4.9Gb...

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Replace a string that contains special characters
3 direct replies — Read more / Contribute
by Sonya777
on Mar 21, 2017 at 11:54
    Hi experts, I need help with an edit of a .txt file. I want to replace a part of the string with an empty space (i.e. remove the part of the string). I have many lines like this one:

    [{"absoluteLimits":{"conditionalLimits":{"bidirVolume":4096000,"name":"Home"},"resetPeriod":{"volume":"monthly day 15 00:??"}},"sliceVolume":5120,"subscriptionDate":"29-09-2016"},{"absoluteLimits":{"conditionalLimits":{"bidirVolume":102400000,"name":"Home"},"resetPeriod":{"volume":"2400 hours"}},"description":"Promotion_tariffbasic:29-09-2016,08-01-2017T10:21","name":"1004","sliceVolume":5120,"subscriptionDate":"30-09-2016T09:21"}]}

    And from this line I want to remove the bolded string. To do this for many lines, basically I need to remove a part of the string that starts with:

    {"absoluteLimits":{"conditionalLimits":{"bidirVolume":102400000,"name":"Home"},"resetPeriod":{"volume":"2400 hours"}},"description":"Promotion_tariffbasic:

    (this is the "common" part for each line, since the date is different for each line) The problem is that the string contains special characters like ",:,} and a simple search & replace script does not work:
    perl -p -e 's/{"absoluteLimits":{"conditionalLimits":[{"bidirVolume":1 +02400000,"name":"Home"}],"resetPeriod":{"volume":"2400 hours"}},"desc +ription":"Promotion_tariffbasic:.*//s' example.txt
    Do you have any idea how this can be done? Thanks a lot! Sonya
Excel SaveAS problem
1 direct reply — Read more / Contribute
by merrymonk
on Mar 21, 2017 at 11:04
    I am having trouble saving an Excel spreadsheet. With Perl I take the steps
    1. Take a copy of a spreadhsheet that has some cells already filled in
    2. Use this copied file with
    $excel = Win32::OLE->new('Excel.Application', 'Quit'); $workbook = $excel->Workbooks->Open<copied file name>) $worksheet = $excel->ActiveWorkbook->Worksheets(“sheet1”);
    3. Fill in the data I need
    4. Try and save the edited copy of the spreadsheet with
    $excel->Workbooks(1)->SaveAs(<copied file name>) or ($excel_res = 0, + $ew_message = "Could not save spreadsheet <copied file name>); $en_num = Win32::GetLastError(); $en_err = "message <" . Win32::FormatMessage($en_num) . "> number <" . + $en_num . ">"; $ew_message = "<" . $ew_message . "> is just after saving part file\n" + . "system error text <$en_err>\n";
    The MSDOS screen gives the following contents for $ew_message
    <Could not save spreadsheet <copied file name> is just after saving part file system error text <message <> number <317>>
    I also get an Excel message saying Do want to save the changes you made to <copied file name> with three buttons for Save, Don’t Save and Cancel.
    If I open the copied spreadsheet (before I use any of the message buttons) I get the message that the file is Locked for Editing.
    If I use the Save button I get the edited spreadsheet that I want.
    What changes do I have to make so that the spreadsheet will be saved as I would like it to?
How to run our folders and files with url using perl program?
5 direct replies — Read more / Contribute
by finddata
on Mar 21, 2017 at 08:27

    I had included the following line in my script to link the url and open its directories from url.

    But am not sure does the url is correct and how to link the folders with url.

    Please help me.Thanks in advance.

    open my $fh, '<', $file or die "Can't open $file: $!"; while (my $line=<$fh>) { chomp $line; for($line) { s/\&//g; s/[\\\_\@\_]//g; s/COMMENT//g; } my @data = split /:/, $line; my $class = $data[0] ? 'normal' : 'bold'; print $fh_out qq[<tr class="$class">]; my $href="http://www.iad.log.com/apps/v/kb/dms"; my $check=0; my $dolink=$data[0] !~ m/[\=\%]/; for my $word(@data){ $check++; print $fh_out '<td>'; if($check==1 && $dolink ) { print $fh_out '<a href="'.$href.'" >'.$word.'</a>'; } else { print $fh_out $word;} print $fh_out '</td>'; } } }

    And How to check does am running with correct url?


Add your question
Title:
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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (1)
    As of 2017-03-23 01:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Should Pluto Get Its Planethood Back?



      Results (278 votes). Check out past polls.