On 26/08/2011 18:12, Jim Gibson wrote:
On 8/25/11 Thu Aug 25, 2011 5:20 PM, "Rob Dixon"<rob.di...@gmx.com>
scribbled:
On 25/08/2011 20:36, Shlomi Fish wrote:
If you want to use $_ so be it, but it can easily introduce subtle errors
into
your code, because $_ is so easy to modify and clobber. So I would recommend
against these, and still think it's a good idea.
Please substantiate this assertion. I believe your recommendation
deserves to be put in the bin of ill-conceived dogma.
Shlomi gave a link to a case where somebody had to find a subtle error
caused by $_ being clobbered. I would only disagree with Shlomi's use of the
term "easily". I hope we can all agree that $_ can be overwritten
inadvertently, but it does not happen very often.
Nevertheless, beginning Perl programmers should be cautioned that it can
happen, and they should be encouraged to use explicitly-named variables for
complex loops and blocks and especially for any block that calls a
subroutine or system function.
We need to respect the people who post here seeking help. They need to be
told about those Perl issues that are not obvious, such as $_ being
overwritten. They do not need to be told "never use $_ by default because it
can be overwritten". It is up to each programmer to choose whether or not to
use $_ as a default variable and risk it getting clobbered by mistake. They
do need the information on which to base this decision.
They also need to be encouraged to use "best practices". However, what
exactly best practices are is open to debate.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/