in reply to Re: My pattern for "in-place edit" for many files
in thread One-shot code critique
Doing so makes it very clear to the reader that this variable doesn't need a long lifetime, and even ensures that the action won't collide with a larger-scoped variable. It's a slick trick, and works nicely.
I've also recently started using the idiom of a one-iteration foreach loop to "name" a value rather than setting up a temporary, like:
It's a nice idiom, and is also the explanation of why Larry intentially allows foreach to be spelled "f-o-r". And the "backwards foreach" makes it even easier:for ($some->complicated(@value)->{$to_fetch}) { print; # print it print LOGFILE $_; # and to the logfile substr($_, 0, 1, ""); # remove its first character }
do_this($_), do_that($_, @moreargs) for $some{$complicated}{$value};
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
For - Loop construct 'cheaper' than local variable?
by C-Keen (Monk) on Sep 29, 2001 at 23:28 UTC | |
by Brovnik (Hermit) on Sep 30, 2001 at 02:44 UTC |