From: "Barry Brevik" <[EMAIL PROTECTED]>
> OK, I've stumped myself. I wanted to assign 0 to several variables,
> except for a single variable that should be set to 1.
> 
> Before I knew what I was doing I whipped this code into my editor:
>  
>   ($frow = $ax = $bx = $cx = 0)++;
>  
> ...and it works as I expected. That is, all of the variables are set to
> 0 except $frow which is 1.
> 
> Now I'm afraid that it might not always work because I don't understand
> why it works in the first case. Anyone want to suggest if this is stable
> code or not?

It will always work, but you should not do it like this.

$frow = 1;
$ax = $bx = $cx = 0;

would be much cleaner.

It works because the assignment "returns" not the value, but the 
variable. That is

($x = 7)++;

is not equivalent to

$x = 7;
7++;

but to 

$x = 7;
$x++;


There are few cases when this is actually fine to use, one of them is

  ($newvar = $oldvar) =~ s/some/transformation/;

in this case again, you assign the value of $oldvar to $newvar and 
then apply the s/// to the $newvar.

Jenda



===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to