which irritates my hubris. Localizing here is better than that, but it's just too much red tape for my taste:$some->{deeply}{nested}{data}{structure} = "kettle" if $some->{deeply}{nested}{data}{structure} eq "pot";
{ local *_ = \$some->{deeply}{nested}{data}{structure}; $_ = "kettle" if $_ eq "pot"; }
local *_ = \$something; is not a language construct, I have to brainparse it and understand what's going on to read the code.
I see where you object to a loop that has only one iteration, although I find the use of redo in a naked block far worse than a single-iteration for loop: the redo conceils the loop character because you don't know that that naked block is one until you read to an arbitrary point inside it. for used as a topicalizer on the other hand makes it immediately obvious that we're only looking at a single iteration.
The example you gave where a function's return value is topicalized misses the point. You topicalize a variable when you intend to modify it - doing that to a function return value you haven't saved is pointless. You might of course do something like this:
But if I had to maintain that I'd hunt you down and kill you. That obviously should have beenmy $stuff; for(return_value()) { chomp; s/foo//g; tr/x/y/; $stuff = $_; }
my $stuff = return_value(); for($stuff) { chomp; s/foo//g; tr/x/y/; }
For the record, I actually don't use the long construct with the for block frequently either. It does come in very handy when it's appropriate though. (I got the idea of using for as a topicalizer from the man himself actually - he mentioned this in an interview, where he said it Perl has a topicalizer, for, which lets people say "it", ie $_, without specifying the subject over and over.)
That's what I have to say on the issue. YMMV :-)
Makeshifts last the longest.
In reply to Re^4: Using $_ as a temp var, especially in functions
by Aristotle
in thread Using $_ as a temp var, especially in functions
by BUU
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |