in reply to "if" in a my declaration statement causes problem
Another possibility, if you still wanted it on one line, would be:
sub sub1 { #... my $x = ( <some condition> ) && $y; #... }
This way, if the condition ended up false, you'd wind up with some false value (although not necessarily undef) in your variable. You could do my $x = ( <some condition> ) ? $y : undef; if you need $x to default to undef, but I'd say Siddartha's solution looks tidier for that case.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: "if" in a my declaration statement causes problem
by TGI (Parson) on Feb 21, 2006 at 18:21 UTC |