Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
In the code below involving a loop, where is the "right" place to declare variable $var - inside or outside the loop?Thanks in advance :)foreach my $elem (@somearray) { my $var = $elem == 10 ? 'found 10' : 'other number'; } my $var; foreach my $elem (@somearray) { $var = $elem == 10 ? 'found 10' : 'other number'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Placement of "my"
by lakshmananindia (Chaplain) on Apr 02, 2009 at 13:29 UTC | |
|
Re: Placement of "my"
by vinoth.ree (Monsignor) on Apr 02, 2009 at 13:39 UTC | |
|
Re: Placement of "my"
by GrandFather (Saint) on Apr 02, 2009 at 21:55 UTC | |
|
Re: Placement of "my"
by Anonymous Monk on Apr 02, 2009 at 14:44 UTC | |
by JavaFan (Canon) on Apr 02, 2009 at 15:48 UTC | |
by Anonymous Monk on Apr 02, 2009 at 16:55 UTC |