>From a newbie perspective, your code is flawed (no offense :)).  Your line:

$sort_order = $ARGV[0] || $usage;

is saying set $sort_order to $ARGV[0] (no matter what it is, or even if it's
defined) or eval (not sure if that's the right word for this context)
$usage.  So the code is doing the first part of the || line and skipping the
2nd part all the time (because it can always set $sort_order).

If you want to be poetic (which I admire, tho I'm still in 'baby talk' mode
;)), you may want to use a ternary op:

$sort_order = ($ARGV[0]) ? $ARGV[0] : $usage;
print "$sort_order\n";

Or:
print $usage && exit unless $ARGV[0];
$sort_order = $ARGV[0];

HTH,

Jason

----- Original Message -----
From: "David Gilden" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, July 16, 2001 10:46 PM
Subject: Cmd Line args


> if I invoke this script as follows:
>
> perl bears.pl
>
> ARGV[0] never seems to be false even though there are no args..
>
> What did I do wrong here?
> Thanks
> Dave
>
>
> #!/usr/bin/perl -w
>
> $sort_order = $ARGV[0] || $usage; # grab command line args
>
> $usage ="
> # Type a number after the script name to choose the type of sorting:
> # 1 = sort by type
> # 2 = sort by name
> # 3 = sort by color
> # 4 = sort by food
> #
> # Example:
> # perl bears.pl 1
> # sorts bears by type";
>
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to