laziness, impatience, and hubris | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Personally, if an intermediate var is used is in more than one line of code (or possibly two), it no longer warrents the nomenclature "temporary". At some point in the future, someone (possibly you:) is going to come along and insert some code between some of the lines where the 'temporary var' is used and that seperates it from its temporaryness (Is that a word?). In any other language I've used, my advice would be to just go ahead and use a locally-scoped (lexical in Perl terminology ie. my $tempSomething). However, the propensity (and utility) of Perl's built-ins to use $_ leads to a slightly ambiguous decision, in that I do use $_ where that makes sense because I am going to apply one or more built-in features which default to that. However, I wouldn't use the for ($thingToAlias) { ... }; as I personally find the one-time-loop construct distracting. In preference I would use a bare block.
To me (who is still experimenting and evolving my Perl Style), this has all the advantages of the 1-time for with none of it's disadvantages. It will be interesting to see if anyone has any arguments against this. Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring! In reply to Re: Using $_ as a temp var, especially in functions
by BrowserUk
|
|