> -----Original Message-----
> From: Bryan R Harris [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, June 11, 2002 11:50 AM
> To: [EMAIL PROTECTED]
> Subject: RE: passing an empty string to a perl script via command line
> 
> 
> 
> Interesting!  It looks like my problem comes from the way I'm reading
> arguments off the command line.  I've been using:
> 
>   $match = shift || die("Usage: rename match-expr 
> replace-expr [filenames]
> \n  example: rename txt html *.txt\n");
>   $replace = shift || die("Usage: rename match-expr replace-expr
> [filenames]\n  example: rename txt html *.txt\n");
> 
> Apparently the shift pulls off the empty string just fine 
> (passed using two
> single quotes ''), but it doesn't return a 1 for the empty 
> string, so the
> script "dies".
> 
> I'm a little vague on the fix, is it immediately clear to someone?

The following are "false": undef, '', and '0'. Everything else is
"true". So you'll have a problem if the replacement string is '0'
as well.

Use defined() instead. This is only false for undef.

   defined($replace = shift) or die "blah blah...";

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

Reply via email to