Friday, July 20, 2007

Nerver/Ever do this: my $foo = $bar if ($cond);

well, I met this a few days ago.
my $foo = $bar if ($cond);
makes a lot of trouble for me.

I view that this is talked in Catalyst maillist.
http://lists.scsys.co.uk/pipermail/catalyst/2007-July/thread.html#14484

And just for your attention, be careful!

example from mst:
sub foo { my $foo if 0; $foo++; }
print foo(), foo(), foo();


guess what it is?

DO NEVER try code like this, instead try my $foo = ($cond) ? $bar : undef;

@Enjoy;

1 Comments:

Anonymous nsnake said...

sub foo { my $foo if 0; $foo++; }
print foo(), foo(), foo();

012
完成

7/23/2007 10:34 AM  

Post a Comment

Links to this post:

Create a Link

<< Home