in reply to Re^3: foreach vs while<>
in thread foreach vs while<>
One this is for certain is that there is no reason to do @a = <$fh>; for (@a) unless you do something else with @a.That's not true. There's an advantage
gives you which@a = <$fh>; for (@a) { .. }
doesn't give you which may be useful sometimes. Doing @a = <$fh> means you're done reading the file before processing it. If you have a lock on the file, you can then release it. But if you are doingwhile (<$fh>) { .. }
you're only done reading the file after you've processed almost everything (and one typically releases a lock after processing everything). Now, most of the time, this doesn't matter because noone else needs the file (so you don't have locks, and the file doesn't get modified), or the processing goes fast (so there isn't much difference).while (<$fh>) { .. }
But it goes to far to say "there's no reason to do @a = <$fh>; for (@a)". Sometimes, there is.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: foreach vs while<>
by ikegami (Patriarch) on Nov 12, 2008 at 17:31 UTC | |
|