Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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
Converting .pl to .exe file
2 direct replies — Read more / Contribute
by mohad
on Jan 30, 2015 at 00:23

    hello All, I'm new to Perl and have written a small code. Now I want this .pl file to be converted into .exe file so that it can run on any system(only windows) without perl being installed. can someone please guide step by step ?

    here is my code:

    use strict; use warnings; use Cwd; my @operations = ( { label => 'Harcoded font size value !!', test => sub { $_[0] =~ /font-size\s*(:|=)\s*[^%]+$/ }, }, { label => 'Forced Line height value !!', test => sub { $_[0] =~ /line-height/ }, }, { label => 'position absolute !!', test => sub { $_[0] =~ /position\s*(:|=)\s*absolute/ }, }, ); my $dirpath = getcwd; my @filepaths = glob( "$dirpath/*.css" ); print "no css files\n" unless @filepaths; for my $filepath ( @filepaths ) { print "\n>>> $filepath <<<\n"; $_->{count} = 0 for ( @operations ); # set or reset counts. open my $filehandle, '<', $filepath or die "could not open '$filep +ath': $!"; while ( my $line = <$filehandle> ) { $_->{test}->( $line ) and $_->{count}++ for ( @operations ); # + for each operation, call the test and increment count if it returns +true. } close $filehandle; print "$_->{label} $_->{count} Instance found\n" for ( @operations + ); # for each operation, print the outcome. }
SOAP::Lite client request over HTTPS hangs until connection is reset by server
No replies — Read more | Post response
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 @_; }

    Thanks!

(in cleanup) Can't call method "close" on an undefined value at somePerlModule.pm line number.
2 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
2 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:
    myserver.com/script.exe?dbNum=1&action=3&CGISESSID=e91b1bfb03f67854f9675b40f6a705ac

    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
3 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 ;)


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!
  • 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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (7)
    As of 2015-01-30 07:07 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My top resolution in 2015 is:

















      Results (248 votes), past polls