in reply to What about if (my $var = foo()) { ... }
if (my $result = some_func()) { # do something with $result }
I use this construct all the time, and am not aware of any problems with it. The conditional is testing the return value of the assignment, which is true if some_func() returns something true. If it's false, then $result gets whatever false value was returned and the block does not execute (or the compiler may optimize away the assignment completely -- I don't know how that works.)
Off hand, I can't think of any reason why this would not also be allowed in Perl 6.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: What about if (my $var = foo()) { ... }
by Limbic~Region (Chancellor) on Dec 29, 2007 at 16:03 UTC | |
by dsheroh (Monsignor) on Dec 29, 2007 at 16:39 UTC | |
by Limbic~Region (Chancellor) on Dec 29, 2007 at 16:49 UTC | |
by dsheroh (Monsignor) on Dec 29, 2007 at 18:46 UTC |