in reply to Ternary Operator for Multiple Arguments Passing
Slightly opaque bug there. ;)
shift without args, in main code is the same as shift @ARGV; I'm sure we agree there. Well, when you shift the first value off of @ARGV, that changes the array, so in your second comparison, you're looking at what used to be the third element.
For example:
#perl mytest.pl sn 5 # Before anything else is done, @ARGV looks like: # $ARGV[0] = 'sn' # $ARGV[1] = '5' my $based_on = $ARGV[0] ? shift: 'tp'; # Now @ARGV looks like this: # $ARGV[0] = '5' # $ARGV[1] = undef my $top = $ARGV[1] ? shift: 1; # It's going to return '1' because $ARGV[1] was undef, due to # the first shift.
What you should try instead is:
my $based_on = defined( $ARGV[0] ) ? $ARGV[0] : 'tp'; my $top = defined( $ARGV[1] ) ? $ARGV[1] : 1;
...or using shift:
my $based_on = defined( $ARGV[0] ) ? shift : 'tp'; my $top = defined( $ARGV[1] ) ? shift : 1;
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Ternary Operator for Multiple Arguments Passing
by eric256 (Parson) on Dec 21, 2005 at 03:38 UTC | |
by davido (Cardinal) on Dec 21, 2005 at 04:16 UTC |