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
SOAP::Lite client request over HTTPS hangs until connection is reset by server
2 direct replies — Read more / Contribute
by kiteboy
on Jan 29, 2015 at 23:34

    Wise monks,

    Iím trying to use a script that sends a SOAP::LITE request over HTTPS. The script was written by a colleague, and while I have a bit of perl experience I have no SOAP or HTTPS apart from reading up the past few days. The script make one SOAP::LITE request to a server, hangs for 60 seconds and then continues as expected with an expected response. It appears the SOAP::LITE request hangs until the connection is reset by the server (causing a 60 sec delay between making the request and being able to process the response).

    I have confirmed that the server response quickly to the request and then the script hangs until the reset is received using tcpdump.

    Here is a sanitized version of the code. Hopefully there is enough to give an idea what it is doing...

    #!perl -w use Net::SSL; use SOAP::Lite; $SOAP::Constants::DO_NOT_USE_CHARSET = 1; use XML::LibXML; my ($function, @params) = @ARGV; $ENV{HTTPS_CERT_FILE} = "./xxxxx.crt"; $ENV{HTTPS_KEY_FILE} = "./xxxxx.key"; my $sitetoken= SOAP::Header->name( CODE REMOVED ); my $ppsoapheader=SOAP::Header->name( CODE REMOVED ); my $auth = SOAP::Header->name( CODE REMOVED ); my $namespace = SOAP::Data->new( CODE REMOVED ); $soap_response = SOAP::Lite -> uri('http://schemas.xxxxx.com/Passport/SoapServices/CredentialSer +viceAPI/V1') -> proxy('https://api.login.yyyyy.com/pksecure/PPSACredentialPK.srf' +) -> GetEDUMigrationData($namespace, $ppsoapheader, $auth);

    Wise monks, any ideas why this is hanging until the server reset is received?

[LWP::UserAgent] 'Can't locate object method "request" via package "1" when attempting to add a hander
1 direct reply — Read more / Contribute
by three18ti
on Jan 29, 2015 at 19:38

    HEllo Monks

    Back at it again. Trying to figure out how to use a handler. I'm following the example Re^5: SOAP::Lite method with one param. When I add the "request_send" handler I receive an error. If I change the name of the handler to "request_done" or "request_prepare" I don't receive an error.

    The error:

    Can't locate object method "request" via package "1" (perhaps you forg +ot to load "1"?) at /usr/local/share/perl/5.18.2/LWP/UserAgent.pm lin +e 216.

    Actually, this appears to be an issue with LWP::UserAgent

    #!/usr/bin/env perl use strict; use warnings; use LWP::UserAgent; use Data::Dumper; my $ua = LWP::UserAgent->new; $ua->add_handler('request_send', \&pp_dump); $ua->post("http://google.com"); sub pp_dump { print Dumper @_; }

    This is the SOAP code I was working with

    #!/usr/bin/env perl use strict; use warnings; use 5.010; use SOAP::Lite; SOAP::Lite->import(+trace => 'all'); use Data::Dumper; my $client = SOAP::Lite->proxy($proxy) ->ns($namespace, 'foo') ->uri($uri) ->on_action(sub { sprintf '%s', $_[0] }) ->on_fault(sub { my($soap, $result) = @_; die ref $result ? "Fault Code: " . $result->faultcode . "\n" . "Fault String: " . $result->faultstring . "\n" : $soap->transport->status, "\n"; }); my $params = { foo => 'bar', biz => 'baz'}; # does not cause error # $client->transport->add_handler("request_prepare", \&pp_dump ); # causes error $client->transport->add_handler("request_send", \&pp_dump ); my $result = $client->call('my_api_method' => $params); sub pp_dump { print Dumper @_; }


(in cleanup) Can't call method "close" on an undefined value at somePerlModule.pm line number.
3 direct replies — Read more / Contribute
by thanos1983
on Jan 29, 2015 at 18:27

    Hello Monks,

    I am seeking your wisdom for once more. I just start implementing for a first time OO programming with Perl. So I was reading online that I should use Destructors. I was also reading How do I make a destructor? and explicitly calling destructor but I can not figure it out how to use it on my modules.

    I am getting the following error on my Perl module. Sample of code is provided under:

    If anyone can provide some input would be great. Thanks in advance for your time and effort.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Testing if a .txt file contains any data
3 direct replies — Read more / Contribute
by sigmaaa
on Jan 29, 2015 at 16:54
    Hey guys,

    So I'm opening a .txt file with perl but I want it to check to make sure there is data written to the file and if not to end the program. So far all I can do is get it to run like there is data or run like there isn't any data regardless if there actually is. I've tried just about everything so at this point I've just made two .txt files and left one blank so I can see if wordlist.txt is equal to shit.txt and if they are to kill the program. Still isn't working though, if you could help that would be great!

    my $wordlist = 'wordlist.txt'; my $highschool = 'bathroom.txt'; open (LIST, $wordlist) || die "\n Cannot find wordlist.txt \n"; open (lol, $highschool) || die "\n Cannot find bathroom.txt \n"; + print "\n professional site \n"; # After opening the two .txt files I'm checking if they are equal because bathroom.txt is a blank file if ($highschool =~ $LIST) { die "\n No data in wordlist.txt \n"; } else { print "\n All clear \n"};
Read files not subdirectories
2 direct replies — Read more / Contribute
by wrkrbeee
on Jan 29, 2015 at 16:29

    Hi PerlMonks, I'm working to create a loop that will read all text (.txt) files in a directory, excluding any sub-directories. Simple enough, think I have the pattern match, but not enough knowledge to incorporate it into the IF or NEXT UNLESS condition. Once the files are read, I'm hoping to strip HTML tags with HTML::STRIP. I am grateful for any insight you may have. Here is the code I am working with:

    #! /usr/bin/perl -w use strict; use warnings; use lib "c:/strawberry/perl/site/lib"; use HTML::Strip; my $hs = HTML::Strip->new(); my $write_dir = 'G:\research\sec filings 10k and 10Q\data\filing docs\ +1993\Clean'; my $files_dir = 'C:\Dwimperl\Perl\1993'; opendir (my $dir_handle, $files_dir) || die "failed to open '$files_di +r' <$!>"; while (my $file = readdir($dir_handle) ) { next if $file eq '.' or $file eq '..';# or $file =~ /[0-9|-]+\.txt +$/; open my $file_handle, "/dwimperl/perl/1993/$file" or die "failed t +o open '$file' <$!>"; foreach my $line (<$file>) { my $clean_text = $hs->parse( ' ' ); print $write_dir "$file\n"; $hs->eof; } } close(); closedir $dir_handle;
How Do I Read An Old DB File?
2 direct replies — Read more / Contribute
by shachter
on Jan 29, 2015 at 14:03
    I am trying to read an aliases.db file that was, apparently, created by an old sendmail program. The “file” command reports:

    Berkeley DB (Hash, version 5, native byte-order)

    and this is, apparently, too old for DB_File to read. I have another aliases.db on another computer which is (according to the “file” command)

    Berkeley DB (Hash, version 9, native byte-order)

    and DB_File reads that one perfectly, so there is nothing wrong with my perl program. Lest you be tempted to tell me to use a more modern DB format for my aliases.db file, I tried that already, and it didn't work. I ran newaliases on my new computer, and sent the newly-generated aliases.db file back to my old computer, and my sendmail program on my old computer couldn't read it, so it was useless. I have to use the version-5 format. How do I write a perl program that can read it? If you do not think that this question is of general interest, please do me the kindness of replying to me at
    jay at m5 dot chicago dot il dot us
    Thank you in advance for any and all replies.
SessionID on a windows server
4 direct replies — Read more / Contribute
by mwhiting
on Jan 29, 2015 at 13:51

    Hi - I have a script that runs on both windows and linux servers. On windows, I use perl2exe to compile it, though I don't think that is the source of the problem here.

    The script uses CGI::Session for Session id's for the purposes of keeping a password from one session to the next. With a Linux/unix server, if you are logged in successfully, and later copy and paste the url from your browser (which contains a parameter with the Session id) into an email and send it to another computer, the second computer doesn't recognize the session id as valid for itself and re-prompts for password (as it should do).

    It would be an url similar to this:

    But on a windows server the same action doesn't result in getting prompted for a password. The server will recognize the sessionID and just continue on as normal, even though noone has ever entered a password on this second pc before.

    Any insights as to why this would be?

Open directory command in perl
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 29, 2015 at 12:25
    HI, I am using perl to open and read a directory which have many files and doing some operation using those files. Need to know how readdir behavior if files being continuosly written to this directory and perl program initiated in b/w?
Help with pp - Perl Packer
4 direct replies — Read more / Contribute
by perloHolic()
on Jan 29, 2015 at 11:08

    Good afternoon.

    THE PROBLEM : I'm afraid I'm having a problem with using pp to create a standalone perl executable. It DOES create a file.out, however running this file does NOT run in the same way as If I ran the script itself.

    THE REASON: The reason I am trying to create a standalone executable is because the program I have written in perl needs to work in our model office environment at work, which is not connected to a network, and has little or no perl modules outside the core modules, and no way of getting them (to the best of my knowledge that is.)

    MY UNDERSTANDING: As far as I am aware, the reason that I need the program to work in an environment where it would not run as a standalone script is a valid reason for making an executable that was self contained with necassary modules -(I had a chat with some very polite monks in the chatterbox).

    MY REQUEST: First and formost I'd like to understand why when I run the executable does it not behave/display in the same way as if I just ran the script? What would also be lovely is if someone could shed some general ambient light around the subject itself (common pitfalls/misunderstandings etc.), as after reading suid Perl with App::PAR::Packer (pp) and Convertion Perl Script to Exe with PAR::Packer pp to try and understand exactly what I was doing wrong, I was no better off. I know what you'll ask next what exactly have you tried? - well I simply ran pp -o file.out file.pl which I belive has created my executable which includes the script and necassary modules, and (stupidly) I thought voila! it worked! - how wrong I was. I run the executable now, and it runs funny , giving me this( : is not an identifier) in the window and the formatting all skewed...?

    As always, my deepest thanks to those who lend an ear, and apologies in advance if I have ommitted any necessities or have made myself unclear, me and the old How do I post a question effectively? don't always get along ;)

Performance comparison Apache/FastCGI/Plack vs Apache/FCGI vs Plack standalone vs Apache/mod_perl (was "New version of Mod_perl")
2 direct replies — Read more / Contribute
by adamarc
on Jan 29, 2015 at 11:02
    thank you stonecolddevin & sundialsvc4.
    You inspired me to look at other options, and I decided to load test all of them with a simple script that connects to a MySQL database to select some UTF8 data, and return it.
    I did the test twice. I included a big Perl module (~650KB) in the second test to check if the compilation phase makes sense.
    All of the configurations properly returned the UTF8 text.
    I did the test on an 8-core Intel 3770 with 16GB of RAM (which was not a bottleneck). OS: FreeBSD 10.0.

    I'm curious to hear about what your opinion is of the below results. I find the number of Apache 2.4/FCGI too good to be true, but could not find any errors. Maybe somebody can replicate the test?

    100 concurrent requests with ~10KB script: Requests Correct Requests Error AVG_msec Apache 2.4/FCGI 202510 0 14 Apache 2.4/FastCGI/Plack 25584 0 116 Plack standalone 17012 0 175 Apache 2.2/mod_perl 1828 1128 185 100 concurrent requests with ~650KB script: Requests Correct Requests Error AVG_msec Apache 2.4/FCGI 55697 0 52 Apache 2.4/FastCGI/Plack 13971 0 213 Plack standalone 13042 0 228 Apache 2.5/mod_perl 1689 0 217

    See here the used scripts, and configuration.

    Apache/FCGI script

    Apache/FastCGI/Plack script
    Plack standalone: the same script as Apache/FastCGI/Plack
    The command that I used to run it: perl ./fcgiplack.fcgi &> fcgiplack.log &

    SQL script to create the used database:

    Initial post with title: New version of Mod_perl Dear respected Perl monks,

    I have a mod-perl site that I want to continue using, but my distro doesn't distribute the mod-perl package anymore because there is none available that works with Apache 2.4. It turns out that the loyal mod_perl development team cannot release a compatible version due to a lack of testers.

    Can somebody help by assisting them in submitting a bug report?

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.