Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by Anonymous Monk
on Oct 18, 2012 at 13:53 UTC ( #999738=note: print w/ replies, xml ) Need Help??


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

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

#!/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; Main( @ARGV ); exit( 0 ); sub Main { local @ARGV = @_; my( $pstart, $ptype, $help ); GetOptions( "t=s" => \$ptype, "s=i" => \$pstart, "h" => \$help ); check_input( $pstart, $ptype, $help ); } sub check_input { my( $date, $type, $help ) = @_; # asking for help is not an error, DO NOT DIE $help and return print_help(); if( !defined $type or !defined $date ) { return print_usage(); } check_date( $date ); if( $type =~ /^[DWMS]$/ ) { print qq{period OK\n}; } else { die qq{Error : the given period is not valid\n}; } } ## end sub check_input sub check_date { my( $s ) = @_; eval { DateTime::Format::ISO8601->parse_datetime( $s ); 1; } or die qq{Error : the date doesn't exist or is not like YYYYMMDD +\n}; print qq{date OK\n}; } sub print_usage { die qq{ USAGE : ./script.pl -t [D|W|M|S] -s [DATE] }; } sub print_help { print qq{ 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 }; } ## end sub print_help __END__ perltidy -csc -csci=10 -cscl="sub : BEGIN END" -otr -opr -ce -nibc -i= +4 -pt=0 "-nsak=*"


Comment on Re: Script using Getopt::Long running endlessly after beeing packaged by pp
Select or Download Code
Re^2: Script using Getopt::Long running endlessly after beeing packaged by pp
by HJO (Acolyte) on Oct 18, 2012 at 14:52 UTC

    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: note [id://999738]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2014-12-21 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls