in reply to How & why does this work?
This works because of an optimisation to use the original array directly, when you're iterating over a single array. Otherwise, a list of the items to iterate over (referencing the original elements) is internally being created on the stack. Try adding an empty list like this
foreach my $path (@all_paths, ()) {
and you'll notice that the "live-update" feature stops working.
That said, I'd like to point out that it's generally not a good idea to rely on such undocumented, implementation dependent behaviour. Also, even though it does work in this particular case, there are several other similar cases where modifying the array you're iterating over (with foreach) will produce unexpected behaviour...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How & why does this work?
by kyle (Abbot) on Jul 11, 2008 at 14:07 UTC | |
|
Re^2: How & why does this work?
by Viki@Stag (Sexton) on Jul 11, 2008 at 14:17 UTC | |
by almut (Canon) on Jul 11, 2008 at 14:30 UTC |