Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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
Cannot re-enter username, password into login form
No replies — Read more | Post response
by GlassKnees
on Aug 01, 2014 at 11:07
    I'm trying to write a perl script that will log into a particular site. There is a bug on the site that issues a bogus error (browser does not accept cookies), and username & passwords are cleared. But if I manually re-enter the username and password, my logi is successful.

    I'm trying to emulate this behavior in perl by testing for the cookies error after my initial login attempt, I repeat the following:
    $mech->set_fields(Username => $username, Password => $password); $mech->submit(); $output_page = $mech->content();
    The resulting behavior is the site responds as if I did not repopulate the username and password fields and simply clicked on the Login button.

    During debugging, I discovered that if I invoke the click() method prior to initially populating the username and password fields, they don't get filled in by the set_fields() method.

    How can I repopulate fields on the same webpage after invoking the click or submit methods?
replacing ActivePerl with Strawberry Perl
3 direct replies — Read more / Contribute
by fionbarr
on Aug 01, 2014 at 09:10
    good morning... I have a working application with ActivePerl 5.18 (Windows7)...I have received advice to replace ActivePerl with Strawberry Perl but I am loath to take the chance of screwing up the work I have done. What are the drawbacks/perils of doing this.
Which rolling log file module do you recommend?
2 direct replies — Read more / Contribute
by bulrush
on Aug 01, 2014 at 08:53
    Which rolling log module do you suggest?

    I found Log::Rolling, the CPAN page said it was at version 1.02, but when I installed it via cpanm, it said I installed v1.00.

    Problem: I have a Perl program that runs continuously and checks email every 30 minutes. At the beginning of a program it opens a log file, and writes entries as the program is run, so I can capture any errors before the program is stopped or crashes. The program can only be stopped by Control-C at the terminal it is running on. Or via an email command sent to it.

    I want to limit the size of this log file to about 1000 lines. I don't need anything complex. Simple will do.

    Thank you.

    After downloading the 1.02 tar.gz file, and installing it, it seems only the internal documentation of the module is wrong. As the .tar.gz file also reported it was installing v1.00.

    Perl 5.8.8 on Redhat Linux RHEL 5.5.56 (64-bit)
Nagios plugin gives “no output returned” using compiled perl
3 direct replies — Read more / Contribute
by aditya1977
on Aug 01, 2014 at 08:42

    I have a custom nagios plugin which is written in Perl. For complicated political reasons I am required to hide the source code of this plugin. The only way I found to do this was by using perlc (

    In the words of author: "Takes a single perl script, converts the block using a simple encoding with an optionally defined key. The script is decoded at runtime and fed to the perl library, to avoid it getting in the hands of the user."

    The problem I am getting is that Nagios shows "No output returned from plugin" when I used the compiled version of the plugin. The raw perl source works just fine, as does running the compiled version on the command line.

    After debugging for a while I narrowed the problem down to using exit in perl. I.e This works fine when compiled.

    print "OK: Everything is working fine.\n";
    This however does not work and results in ""No output returned from plugin"
    print "OK: Everything is working fine.\n"; exit 1;
    It doesn't matter how I exit (0 1 2 or 3) I still get the same problem. I've tried POSIX::_exit(0) instead but no difference?

Give hyperlink to text perl
3 direct replies — Read more / Contribute
by Shivangi17
on Aug 01, 2014 at 06:43

    Hi all,

    This is my first post to perlmonks and i am new to perl

    I have a text document and i want to add hyperlinks to text. please suggest me how to give hyperlinks in perl? for example:


    i have columns in csv format and i want to give hyperlink to XYZ. means when i click on XYZ it should go to


Archive::Zip error when reading a zip file format error: bad signature
1 direct reply — Read more / Contribute
by mhd.tahawi
on Aug 01, 2014 at 05:55
    I have a zip file created by the zip command in Ubuntu and updated by the Archive Manager included in Ubuntu.
    I was trying to read the members of that archive using PERL as follows:
    use strict; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new(); unless ($zip->read('/home/mohamad/Desktop/VM/') == AZ_OK ){ die 'read error'; } my @files = $zip->memberNames(); print join("\n" , @files) ."\n";
    This zip file is about 12 GB and I know that this module has the limitation of zipping no more than 4 GB, but I am trying to see if it can at least be used to access the members of a a +4GB archive. here is the error I am getting:
    at /usr/share/perl5/Archive/ line 477. Archive::Zip::_readSignature('IO::File=GLOB(0xb75ae8)', '/home/mohamad/Desktop/VM/') called at /usr/share/perl5/Archive/Zip/ line 603 Archive::Zip::Archive::readFromFileHandle('Archive::Zip::Archive= +HASH(0xb75c20)', 'IO::File=GLOB(0xb75ae8)', '/home/mohamad/Desktop/VM/') called at /usr/share/perl5/Archive/Zip/ line 548 Archive::Zip::Archive::read('Archive::Zip::Archive=HASH(0xb75c20) +', '/home/mohamad/Desktop/VM/') called at line 6 read error + at line 7.
    my questions are:
    • Is this error the result of a having a + 4GB zip file and due to the module limitation , or it is something else ?
    • if this is due to the 4 GB limitation, what other modules can provide the same functionality ?
    • what I really need from Archive::Zip is the ability to rename file members inside the Archive. Thank you for help.
use of $*
4 direct replies — Read more / Contribute
by millan123
on Aug 01, 2014 at 04:36
    I am seeing old perl code 5.001 where i can see code as below.
    $old = $*; $* =1;
    Came to know $* is deprecated. But not able find what does it mean.please let me know what does it work and which special variable is used in place of $* in higher versions of Perl.
Perl (Net::SSH::Perl) script sometimes hangs while running remote command but shell script works
1 direct reply — Read more / Contribute
by Technext
on Aug 01, 2014 at 02:55
    I have written a Perl script which copies deliverable on machine A (and also takes a backup of the same on another machine B) and then invokes a shell script which is already present on machine A. This shell script deploys the deliverable (generally a war file) on machine A. Though this whole task of copying and invoking the shell script could have been written in bash quiet easily, I thought of using Perl just because I had not written Perl program for quite some time. We have a master-slave setup of Jenkins and the Perl script runs from Jenkins slave.
    use strict; use warnings; use Cwd; use File::Copy; use Getopt::Long; use File::Basename; use Net::SSH::Perl; use Net::SCP::Expect; my ($conf_file, $environment, $action, $job, $dest_file, $user, $host, + $IP, $TARGET_SERVER, $JOB_ENV, $JENKINS_JOB, $wrapper, $src_file, $s +rc_path, $src_dist_path, $src_dist_full_path, $dist_temp_archive_path +, $dist_archive_host, $archive_user, $scpe, $id_file, @id_file, @arra +y, $line); my $ITE = ""; if ($environment eq "release") { $IP = $ITE; $JOB_ENV = "Release_"; $JENKINS_JOB = substr $ENV{'JOB_NAME'}, 8; $dist_temp_archive_path = "/home/ec2-user/release_archive"; } $conf_file = "/home/ec2-user/SCM/generic/deploy_build.cnf"; open (FH, "<", $conf_file) or die "Cannot open < $conf_file: $!"; while (<FH>) { if ( $_ =~ /\b$JENKINS_JOB\b/ ) { push @array, $_; } else { next; } } foreach $line (@array) { ($job, $src_dist_path, $dest_file, $user, $wrapper) = split(':', $ +line); if ($dest_file eq "") { ($src_file, $src_path) = fileparse($src_dist_path); $dest_file = $src_file; } $job = $JOB_ENV . $job; $id_file = "/home/ec2-user/.ssh/sandy"; @id_file = ("/home/ec2-user/.ssh/sandy"); if ($action eq "copy_distributable") { printf "Initiating subroutine to copy distributable on remote +machine...\n"; &copy_distributable; } elsif ($action eq "exec_wrapper") { if (defined $wrapper && length $wrapper) { printf "Initiating subroutine for executing wrapper on rem +ote machine...\n"; &exec_wrapper; } else { printf "*** No wrapper specified ****\n"; } } } sub copy_distributable { $archive_user="ec2-user"; $src_dist_full_path = "$ENV{WORKSPACE}/$src_dist_path"; $dist_archive_host = "55.666.77.88"; if ( -f $src_dist_full_path ) { $scpe = Net::SCP::Expect->new(identity_file => $id_file, host +=> $dist_archive_host); $scpe->scp("$src_dist_full_path", "$dist_temp_archive_path/$de +st_file"); $scpe = Net::SCP::Expect->new(identity_file => $id_file, host +=> $IP, user => $user); $scpe->scp("$src_dist_full_path", "/home/$user/$dest_file"); printf "Deliverable copied on deployment machine. Now moving o +n to next task of archiving the deliverable...\n\n"; my $ssh = Net::SSH::Perl->new($dist_archive_host, "identity_fi +les" => \@id_file); $ssh->login($archive_user); printf "mv $dist_temp_archive_path/$dest_file $dist_temp_archi +ve_path/latest\n\n"; my($stdout, $stderr, $exit) = $ssh->cmd("mv $dist_temp_archive +_path/$dest_file $dist_temp_archive_path/latest"); printf "Output: $stdout\n" if $stdout; printf "Error: $stderr\n" if $stderr; printf "Deliverable archived on Jenkins master\n"; } else { printf "Deliverable not found\n"; exit 1; } } sub exec_wrapper { my $ssh = Net::SSH::Perl->new($IP, "identity_files" => \@id_file); $ssh->login($user); my($stdout, $stderr, $exit) = $ssh->cmd("~/release/$wrapper"); printf "Output: $stdout\n" if $stdout; printf "Error: $stderr\n" if $stderr; }

    Details of Jenkins slave box where the build workspace is:

    [ec2-user@jenkins_slave2 ~]$ uname -a Linux jenkins_slave 3.10.35-43.137.amzn1.x86_64 #1 SMP Wed Apr 2 09:36 +:59 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux [ec2-user@jenkins_slave2 ~]$ free -m total used free shared buffers + cached Mem: 7228 5688 1539 0 72 + 3824 -/+ buffers/cache: 1791 5436 Swap: 16382 163 16219

    Also, there is sufficient memory on the box where the deliverable is copied and finally deployed. Disk space is also not an issue on either of the machines. Both are Linux instances running on AWS.

    Now the issue is that though the program runs fine, many a times, it stucks when the deployment script (shell script) is called. To debug, i ran the Perl script in Jenkins using Devel::Trace. When the build got stuck, I aborted the build. As soon as I aborted the build, I got heap space error so I added Xms & Xmx parameters to set initial and maximum Java heap size respectively. After confirming that the settings are applied, I ran the builds again. Few builds passed and few again got stuck. I don’t think increasing heap size further makes any sense. A shell script was written to do the same task and it does not require any such extra memory to run. Now I am not sure where to look for clues.

    Any help will really be appreciated.
$ARGV[0] meaning
4 direct replies — Read more / Contribute
by grewal7634
on Aug 01, 2014 at 02:43

    I have a perl script containing line $input= $ARGV[0];What does $ARGV[0] stands for in this line?

24 hour to 12 hour using DateTime
1 direct reply — Read more / Contribute
by htmanning
on Aug 01, 2014 at 00:18
    Monks, I'm using this:
    use DateTime qw( ); my $dt = DateTime->now( time_zone => 'Pacific/Honolulu' ); my $dateadded_time = $dt->strftime("%k:%M"); my $dateadded_date = $dt->strftime("%b %e, %Y");
    The problem is %k shows up as 24 time. I'm having trouble figuring out how to get this back to 12 hour time if the hour is more than 12. Thanks!

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 rifling through the Monastery: (14)
    As of 2014-08-01 16:57 GMT
    Find Nodes?
      Voting Booth?

      Who would be the most fun to work for?

      Results (33 votes), past polls