Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Script using Getopt::Long running endlessly after beeing packaged by pp

by HJO (Acolyte)
on Oct 16, 2012 at 09:46 UTC ( #999269=perlquestion: print w/ replies, xml ) Need Help??
HJO has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I'm trying to package a script with pp to run it on another system as a binary file (with Perl itself and every modules I'm using included).

My problem is in the use of the module Getopt::Long... When I launch the script before it has been packaged, I got no trouble with my options, but once it's benn through pp, it runs endlessly (I'm at 100% CPU right now, 1,7GB out of 2GB of RAM and that for around one hour for a scrpit that connects to a system, retrieves data and print them in a file...) Without the packaging, it takes less than a minute to be completed...

Here is my script (only the fraction where I'm using the options I've passed) :

#!/usr/bin/perl # $Id "Getopt::Long Test after packaging by pp" $ # $Revision: 0 $ # $Source /home/root-hjo/script.pl $ use strict; use warnings; use Getopt::Long; use DateTime::Format::ISO8601; my ($pstart, $ptype, $help); GetOptions( "t=s" => \$ptype, "s=i" => \$pstart, "h" => \$help ); ###################################################################### +####### # MAIN + ############################################################### +############## check_input($pstart, $ptype, $help); ###################################################################### +####### # FUNCTIONS + ############################################################### +############## #################################check_input########################## +####### sub check_input { my ($date, $type, $help) = @_; if ( ( (defined($type) == '0') || (defined($date) == '0') ) && (de +fined($help) == '0') ) { die qq{Error while calling script\nUSAGE : ./script.pl -t [D|W +|M|S] -s [DATE]\n\n}; } if (defined($help) == '1') { print_usage(); die qq{\n}; } else { if (defined($type) == '1' ){ if (($type ne 'D') && ($type ne 'W') && ($type ne 'M') && +($type ne 'S') ) { die qq{Error : the given period is not valid\n}; } else {print qq{period OK\n}}; } if (defined($date) == '1') { check_date($date); } } } ###################################################################### +####### #################################check_date########################### +####### sub check_date { my $s = $_[0]; my $date; eval { $date = DateTime::Format::ISO8601->parse_datetime("$s"); }; if ( $@ ) { die qq{Error : the date doesn't exist or is not like YYYYMMDD\ +n} } else {print qq{date OK\n}} ; } ###################################################################### +####### ###############################print_usage############################ +####### sub print_usage { print qq{\n}; print qq{USAGE : ./script.pl -t <D|W|M|S> -s [DATE]\n}; print qq{\n}; print qq{ -t specifies the type of period for which the inf +ormation\n}; print qq{ is retrieved\n}; print qq{ D scale : day\n}; print qq{ W scale : week\n}; print qq{ M scale : month\n}; print qq{ S scale : a few seconds\n}; print qq{\n}; print qq{ -s start date to retrieve data\n}; print qq{ (format YYYYMMDD)\n}; print qq{\n}; print qq{ -h displays this help then stops\n}; } ###################################################################### +####### __END__

And here is the command I'm using to package my script :

# pp -o script -M Getopt::Long -M Params::Validate::XS -M Class::Load::XS -M DateTime::Format::ISO8601 -C script.pl

I'm not directly using Params::Validate::XS nor Class::Load::XS, but it won't simply package if I don't include them so...

And if it helps, here are my output while I'm running this script before packaging :

# ./script.pl -h USAGE : ./script.pl -t <D|W|M|S> -s [DATE] -t specifies the type of period for which the information is retrieved D scale : day W scale : week M scale : month S scale : a few seconds -s start date to retrieve data (format YYYYMMDD) -h displays this help then stops # ./script.pl -t D -s 20121015 period OK date OK

Regards, HJO

Comment on Script using Getopt::Long running endlessly after beeing packaged by pp
Select or Download Code
Re: Script using Getopt::Long running endlessly after beeing packaged by pp
by Anonymous Monk on Oct 16, 2012 at 18:18 UTC

    Works for me

    $ pmvers PAR PAR::Packer Module::ScanDeps PAR: 1.006 PAR::Packer: 1.013 Module::ScanDeps: 1.09

    Try to turn on debugging and see what you get

      Hi, and thanks for your answer.

      But I don't understand why you checked the version of your module Module::Scandeps... Otherwise, I checked the version of my modules to check if they were at the same one than yours, and PAR wasn't, so I upgraded it and when I tried again to package and run I got some other errors :

      # ./script -t D -s 20121015 The following parameter was passed in the call to DateTime::Format::Bu +ilder::Parser::create_single_parser but was not listed in the validat +ion options: params at DateTime/Format/Builder/Parser.pm line 311 DateTime::Format::Builder::Parser::create_single_parser('undef +', 'params', 'ARRAY(0x62cd4c0)', 'length', 8, 'regex', 'Regexp=SCALAR +(0x62cd480)') called at DateTime/Format/Builder/Parser.pm line 501 DateTime::Format::Builder::Parser::sort_parsers('DateTime::For +mat::Builder::Parser', 'HASH(0x625ac40)', 'ARRAY(0x625a1d0)') called +at DateTime/Format/Builder/Parser.pm line 397 DateTime::Format::Builder::Parser::create_multiple_parsers('Da +teTime::Format::Builder::Parser', 'HASH(0x625ac40)', 'HASH(0x62cd4a0) +', 'HASH(0x62cd580)', 'HASH(0x62c4590)', 'HASH(0x62c4630)', 'HASH(0x6 +2c46e0)', 'HASH(0x62c4800)', 'HASH(0x62c4910)', ...) called at DateTi +me/Format/Builder/Parser.pm line 600 DateTime::Format::Builder::Parser::create_parser('DateTime::Fo +rmat::Builder::Parser', 'ARRAY(0x6207400)', 'HASH(0x62cd4a0)', 'HASH( +0x62cd580)', 'HASH(0x62c4590)', 'HASH(0x62c4630)', 'HASH(0x62c46e0)', + 'HASH(0x62c4800)', 'HASH(0x62c4910)', ...) called at DateTime/Format +/Builder.pm line 156 DateTime::Format::Builder::create_parser('DateTime::Format::Bu +ilder', 'ARRAY(0x62e8160)') called at DateTime/Format/Builder.pm line + 174 DateTime::Format::Builder::create_end_parser('DateTime::Format +::Builder', 'ARRAY(0x62e8160)') called at DateTime/Format/Builder.pm +line 104 DateTime::Format::Builder::create_class('undef', 'parsers', 'H +ASH(0x62ea250)') called at DateTime/Format/ISO8601.pm line 173 require DateTime/Format/ISO8601.pm called at script/script.pl +line 8 main::BEGIN() called at DateTime/Format/ISO8601.pm line 0 eval {...} called at DateTime/Format/ISO8601.pm line 0 require main called at /usr/lib/perl5/site_perl/5.8.8/PAR.pm l +ine 636 PAR::_run_member('Archive::Zip::ZipFileMember=HASH(0x5b895d0)' +, 1) called at script/main.pl line 26 require main called at /usr/lib/perl5/site_perl/5.8.8/PAR.pm l +ine 636 PAR::_run_member('Archive::Zip::ZipFileMember=HASH(0x5b89400)' +) called at /usr/lib/perl5/site_perl/5.8.8/PAR.pm line 428 PAR::import('PAR') called at -e line 953 eval {...} called at -e line 209 __par_pl::BEGIN() called at DateTime/Format/ISO8601.pm line 0 eval {...} called at DateTime/Format/ISO8601.pm line 0 Compilation failed in require at script/script.pl line 8. BEGIN failed--compilation aborted at script/script.pl line 8.

      And I don't really understand, should I turn on the Perl debugger while running my script or the PAR debugger while packaging ? (And as I never turned on the debugger, what is the correct synthax ? PAR_GLOBAL_DEBUG=1 ?)

      Regards

        I don't understand why you checked the version

        To show you what I am using

        And I don't really understand, should I turn on the Perl debugger while running my script or the PAR debugger while packaging ?

        I don't know, what are you trying to debug, the packing or the running? Where is the problem?

        (And as I never turned on the debugger, what is the correct synthax ? PAR_GLOBAL_DEBUG=1 ?)

        See help set or  help export depending on your platform, see Environment variable

Re: Script using Getopt::Long running endlessly after beeing packaged by pp
by Anonymous Monk on Oct 18, 2012 at 13:53 UTC

    Instead of large comment MAIN a sub Main

    Instead of  defined($type) == '0' write  !defined $type or  not defined $type

    Instead of  defined($date) == '1' write  defined($date) or defined $data

    So without changing too much of your program write that as

      Well, thanks for the formatting tips, guess I'll pass Perl::Critic much easier now^^

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://999269]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-07-28 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls