On Thu, 26 Jul 2001, Bob Bondi wrote:

> Probably not a Perl bug, but this is so confusing I' probably
> enter it as a bug....
>
> Given the script below and the fact that you run it like: 
> >   perl foo.pl -p 10.0.0.1 -s 8080 -t SOS
> 
> what would you expect the output to be?
>  
> use strict;
> use Getopt::Std;
>  
> my %opts = ();
> getopt('pst', \%opts);
> my $proxy = $opts{p};
> my $serviceport = $opts{s};
> my $this_string = $opts{t};
> 
> if  ($this_string == "all") {
>     print "WHY AM I HERE\n";
>   }
> else {
>     print "YES! I AM HERE\n";
>   }
> 
> I'd expect: YES! I AM HERE, yet what I get is: WHY AM I HERE.
> 
> Please, any help on this one will be happily accepted.

Since you're comparing a string value in the conditional, you need to
use "eq" rather than "==", which is for numeric testing only.

I always run my scripts with the "-w" flag, because it will advise you
of these kinds of errors in advance:

% perl -w foo.pl -p 10.0.0.1 -s 8080 -t SOS
Argument "all" isn't numeric in numeric eq (==) at driver.pl line 11.
Argument "SOS" isn't numeric in numeric eq (==) at driver.pl line 11.
WHY AM I HERE

hth,
Dan


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

Reply via email to