in reply to strange scope

By doing this,

 if (my $x = 1)

You are testing if the variable assignment works which is the wrong way to approach this problem. Try this,

my $x = 1; if ($x > 1) { } # Do something if greater than one elsif ($x < 1) { } # Do something else here

Replies are listed 'Best First'.
Re^2: strange scope
by graff (Chancellor) on May 23, 2007 at 01:48 UTC
    It wouldn't be hard to imagine a situation where you want test the returns from a list of functions, attempted in sequence until one of them returns true, and then do some specific block of code depending on which one returned true. In other words, something like this could be called for:
    my @params = ...; # whatever sets the context... if ( my $x = function_1( @params )) { # do something with the return value from function_1 } elsif ( $x = function_2( @params )) { # do something with the return value from function_2 } # ... and so on.
    I don't know if this is the OP's situation, but it would motivate the kind of approach the OP is asking about. There might be other idioms for doing this sort of thing, but doing it this way seems reasonable.