in reply to Checking Wrong Condition
The regex you used are not matching, are your if statements in a subroutine? If not why use a 'return'
However, the code below could guide you:
use warnings; use strict; die "Enter proper CLI arugments: ......." unless @ARGV == 2; ## check your arguments passed from CLI my ( $num1, $num2 ) = show_now(@ARGV); print $num1, "\t", $num2, $/; sub show_now { my ( $inp1, $inp2 ) = @_; print "inp1 is $inp1 inp2 is $inp2\n"; my ( $opt1, $value1, $opt2, $value2 ) = ""; if ( $inp1 =~ /rel=.+?/i ) { ## changed the regex ( $opt1, $value1 ) = split( /=/, $inp1 ); } if ( $inp2 =~ /file=.?+/i ) { ## changed the regex ( $opt2, $value2 ) = split( /=/, $inp2 ); } if ( $inp1 !~ /rel=.+?/i or $inp2 !~ /file=.+?/i ) { print "\n[Error] - Wrongly passed the parameter.\n"; print " Please use correct format as below\n"; print "\n[Example] - <scriptname> rel=<release> file=<file_name>(\$script_na +me rel=102b file= ccmsg.1)\n\n"; #exit; ## not really needed } return ( $value1, $value2 ) if wantarray(); }
Hope this helps
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Checking Wrong Condition
by Divakar (Sexton) on Apr 25, 2012 at 17:30 UTC | |
by 2teez (Vicar) on Apr 26, 2012 at 00:23 UTC |