#!/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 -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=*"