in reply to Re: Pearls (not really) of Perl programming
in thread Pearls (not really) of Perl programming
I've done that! For two reasons, one good, one bad.
Bad Reason
I thought
for my $i (1..10) { # some stuff with $i }
was the same as
my $i; for $i (1..10) { # some stuff with $i }
rather than being the same as
{ my $i; for $i (1..10) { # some stuff with $i } }
because in C++, (IIRC)
.for (int i=0, i<5; i++) { ... } // i in still in scope here!
I didn't do use int as shown here, but my coworkers did and I would find it misleading. Perl doesn't have that problem, but I only learned that recently.
Good Reason
This fails ('Modification of a read-only value attempted')
foreach my $var ('a', 'b') { ...something that may modify $var... print($var); }
but this doesn't
foreach ('a', 'b') { my $var = $_; ...something that may modify $var... print($var); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Pearls (not really) of Perl programming
by revdiablo (Prior) on Nov 24, 2004 at 21:17 UTC | |
|
Re^3: Pearls (not really) of Perl programming
by Anonymous Monk on Nov 25, 2004 at 18:11 UTC | |
by ikegami (Patriarch) on Nov 25, 2004 at 19:00 UTC | |
by Anonymous Monk on Nov 26, 2004 at 23:25 UTC |