Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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
IO::Compress::Gzip file close issues
2 direct replies — Read more / Contribute
by Paul.Unix
on Jul 26, 2016 at 07:08
    I encountered an issue with IO::Compress::Gzip. After a successful gzip I want to unlink the original file but sometimes the unlink fails with a "permission denied" I made a pragmatic work around by adding a delay and try the unlink again. But a good solution would be preferred. The same issue happens with moving the new .gz to another directory. The files are not in use by another process. Running Strawberry Perl 5.22.0 on Windows 2008 and 2012
    use warnings; use strict; use POSIX; use Cwd; use Cwd 'abs_path'; use Time::Local 'timelocal_nocheck'; # used for SCHEDULE option in +the MQX.ini use Net::Domain qw(hostname hostfqdn hostdomain domainname); use File::Basename; use File::Copy; use IO::Compress::Gzip qw(gzip $GzipError) ; use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; # module used in the state messages use Digest::MD5; # modules used in put mode use threads; use threads::shared; use Thread::Queue; if ( gzip $archfile => "$archfile.gz", AutoClose => 1, BinModeI +n => 1 ) { my $delete_try_counter = mqx_get_setting('ARCHIVEMOVETRY'); while ( -f $archfile and not unlink $archfile and $dele +te_try_counter != 0 ) { $global_EVENTLOG_IN_LQ->enqueue("WARNING, $arch_ha +shref->{'EVENTLOG'},Can not delete $archfile. Error: $! try: $delete_ +try_counter"); $delete_try_counter -= 1; sleep(mqx_get_setting('ARCHIVEMOVEWAIT')); # wait x sec +onds before retrying } $archfile .= ".gz"; # add .gz to the file name } else { # if the gzip failed try to arc +hive the original file $global_EVENTLOG_IN_LQ->enqueue("ERROR, $arch_hashref->{' +EVENTLOG'}, gzip failed on $archfile\n$GzipError"); }
how to get active web page by Perl
1 direct reply — Read more / Contribute
by liuweichuan
on Jul 26, 2016 at 02:45
    how to get flighting info from this web site. i used these code, but i cann't get any info.
    use LWP::UserAgent; use Encode; my $content = LWP::UserAgent->new->get(' +neway_list.htm?searchDepartureAirport=%E5%A4%A7%E8%BF%9E&searchArriva +lAirport=%E5%8C%97%E4%BA%AC&searchDepartureTime=2016-07-28&searchArri +valTime=2016-07-31&nextNDays=0&startSearch=true&fromCode=DLC&toCode=B +JS&from=flight_dom_search&lowestPrice=null')->content;
    who know how to do it, get an active page or ajax page, plz help me get this url's web info.
how to save dynamically added html rows to database using perl
3 direct replies — Read more / Contribute
by marichika
on Jul 26, 2016 at 01:20
    <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTa +ble')" /> <TABLE id="dataTable" width="900px" align="center" border="1"> <TR> <TH>Chk</TD> <TH>From</TH> <TH>TO</TH> <TH>Activities Performed</TH> <TH>Format</TH> <TH>Time</TH> </TR> </TABLE> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox";"chkbox[]"; cell1.appendChild(element1); var from = row.insertCell(1); var element2 = document.createElement("input"); element2.type = "text";['width'] = '100px'; = "txtbox[]"; from.appendChild(element2); var to = row.insertCell(2); var element3 = document.createElement("input"); element3.type = "text";['width'] = '50px'; = "txtbox[]"; to.appendChild(element3); var act = row.insertCell(3); var element4 = document.createElement("input"); element4.type = "text";['width'] = '500px'; = "txtbox[]"; act.appendChild(element4); var format = row.insertCell(4); var element5 = document.createElement("input"); element5.type = "text";['width'] = '50px'; = "txtbox[]"; format.appendChild(element5); var time = row.insertCell(5); var element6 = document.createElement("input"); element6.type = "text";['width'] = '50px'; = "txtbox[]"; time.appendChild(element6); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } </script>
    Here is my perl script
    <table width='100%' > <tr><td align=center><input type=button name='add' value='Add' + onclick='Add_Form(this.form)' accesskey="s" title="alt+s"></td></tr> + </table> function Add_Form(frm) { alert('came'); var url = ' +ession=$session_id'; frm.action=url; frm.submit(); }
    how to send this dynamically added table data to Add_App_Entry page? Thanks in advance Lakshmi
Error saying “Undefined subroutine xxx called at…”
2 direct replies — Read more / Contribute
by bill5262
on Jul 25, 2016 at 22:01

    I have a module imported in my main perl file as the following:

    use rns_fsq_jw;

    The above contains a bunch of sub functions, and it seems to be working well except for one sub fuction:


    This what I have under the rns_fsq_jw library:

    sub ConnectFSQ #ipaddress { (do something blah blah blah) }

    However, when I call the ConnectFSQ() function from my main script, I get the error saying "Undefined subroutine &main::ConnectFSQ called at ..."

    my $IP_FSQ = ""; # ip address ... (blah blah blah) ConnectFSQ($IP_FSQ);

    Am I doing something wrong?

print all files is soo slow! Why?
4 direct replies — Read more / Contribute
by harangzsolt33
on Jul 25, 2016 at 21:30

    I want to write a simple perl program that goes through the current folder recursively and looks at each item, if it's a file, print its contents and moves on to the next one.

    I am a beginner Perl programmer, and I don't know why this is happening, but this perl program stops responding, and then I have to kill it every time.

    I am using TinyPerl 5.8 under Windows 7.

    I am testing this program in a folder that has about 50 text files and no folders. When I launch my perl program, it seems to work perfectly fine, but it doesn't go back to command prompt. It just hangs. The cursor stops blinking, and I have to kill the process.

    If I only read the first 100 bytes of each file, then there's no issue. I am back to command prompt immediately. If I read the first 2000 bytes, then there's a 3-second delay. And I tried reading the entire file and print the content, but then after executing the script, it stopped responding and I had to kill it.

    use strict; use warnings; my $PATH = '.'; my $CONTENT; explore($PATH); sub explore { my $PATH = shift; my $FILE; my $SUB; opendir(my $DIR, $PATH) or return; while (my $SUB = readdir $DIR) { next if $SUB eq '.' or $SUB eq '..'; $SUB = "$PATH/$SUB"; # If it's a folder, explore it. # If it's a file, print it. if (-d $SUB) { explore($SUB); next; } if (-f $SUB) { open($FILE, '<:raw', $SUB) or next; read($FILE, $CONTENT, 2000) or next; close($FILE); print $CONTENT; $CONTENT = ''; # don't need this data anymore } } close $DIR; }
perl dancer route template hashref pass complex json file to server issue
2 direct replies — Read more / Contribute
by RamiD
on Jul 25, 2016 at 16:11
    Hi , I have a problem with perl dancer post parameter to server with template hashref way, the param is json object, if the json object is simple , it work fine mean that perl subroutine template hashref send the json param obj as it should but if I have more complex json file eg. {"name":"jsonFileexample","problem":"thisIsThrProblem\"withComma"} if this is the json file with comma inside one of the json file param , perl hash ref delete the \ from the file , it will look like this {"name":"jsonFileexample","problem":"thisIsThrProblem"withComma"} which will be not a valid json file , how can I send paran (json file) from perl dancer route template param to server as is , without perl changing my json file !!
@INC not set for perlbrew
3 direct replies — Read more / Contribute
by Alessandro
on Jul 25, 2016 at 14:07

    Hi monks,

    I am on os x El capitan and have perlbrew installed. However, when I install a perl module I can't get it working, because it seems perl is not looking at the right place.

    Can't locate WWW/ in @INC (you may need to install the WWW::Mechanize module) (@INC contains: /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2/darwin-thread-multi-2level /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .)


     which perl returns  /opt/local/bin/perl5

    my understanding is that it should return the path to perlbrew install and not the system perl.

    and  perl -v returns  This is perl 5, version 22, subversion 2 (v5.22.2) built for darwin-thread-multi-2level and I indeed used perlbrew to install and switch to perl 5.22.2 but it seems somehow, the "switch" was only partial. What am I missing here?


Recommendations on a module for web crawling
1 direct reply — Read more / Contribute
by edimusrex
on Jul 25, 2016 at 13:59

    I am trying to crawl a web page where the data I am seeking is generated by javascript. I haven't had to deal with this before but I can imagine I am not the only one who has come across this. Is there a specific module that is preferred in this instance? I've tried using Mechanize::Firefox but the page complains about unsupported browser. I'd prefer to do this in perl but will use other languages if need be.

    Thanks for your recommendations

building sql statement
3 direct replies — Read more / Contribute
by mwill007
on Jul 25, 2016 at 13:42

    I have to update database manually alot, so I wrote an app that reads the first line of a csv file and creates the headers/tables for an insert or update statement. The next lines are the data in the file.

    I build the statement like so

    if ($checksite eq $none) { $insertsqlstatement = 'INSERT INTO database.database('; $x=0; foreach (@dbcolumn) { $insertsqlstatement = $insertsqlstatement . "@dbcolumn[$x]"; # if ($x != $numelements ) { $insertsqlstatement = $insertsqlstatement . ","; } # else { $insertsqlstatement = $insertsqlstatement . ') VALUES ('; } # $x=$x+1; } # $x=0; foreach (@dbcolumn) { $insertsqlstatement = $insertsqlstatement . '\'' . "@splitarray[$ +x]" . '\''; $splitstatement = $splitstatement . '$' .@dbcolumn[$x] ; # if ($x != $numelements) { $insertsqlstatement = $insertsqlstatement . ','; $splitstatement = $splitstatement . ','; } # else { $insertsqlstatement = $insertsqlstatement .')'; } $x=$x+1; } }

    when I print the value of $insertsqlstatement is equal to INSERT INTO database.database(site_id, site_store_type, project, site_city, site_state, site_country, project_begin ) VALUES ('9999','SC OSR','Prebuild','Penfield','NY','US','8/8/2016 ')

    I can copy it an it runs just fine in sql

    Buy when i write from my sql statement it will not write sqlexec($insertsqlstatement);

    But if i manualy set the value of $insertsqlstatement = "INSERT INTO database.database(site_id, site_store_type, project, site_city, site_state, site_country, project_begin ) VALUES ('9999','SC OSR','Prebuild','Penfield','NY','US','8/8/2016 ')";

    The sqlexec($insertsqlstatement); executes and updates the database

Push values into a hash
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 25, 2016 at 10:37
    Hi Monks!

    I need to add values into a hash to create a JSON file. Is there a better way to do this. Here is the code I am trying:
    #!/usr/bin/perl use strict; use warnings; use Data::Dump 'pp'; use Data::Dumper; use JSON; my %data; foreach my $number (@{ $names }) { $data{name} = $claim->{"n_names"}; $data{address} = $claim->{"n_add"}; $data{phone} = $claim->{"n_phone"}; $data{email} = $claim->{"n_email"} || ''; push \%data, $data{name}, $data{address}, $data{phone}, $data{email +}; } my $json = encode_json \%data; print Dumper $json;
    Thanks for helping!

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
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (16)
    As of 2016-07-27 14:46 GMT
    Find Nodes?
      Voting Booth?
      What is your favorite alternate name for a (specific) keyboard key?

      Results (243 votes). Check out past polls.