Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH] git-svn: Don't rely on $_ after making a function call

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:07

Eric Wong [off-list ref] writes:
Adam Roben [off-list ref] wrote:
quoted
Many functions and operators in perl set $_, so its value cannot be relied upon
after calling arbitrary functions. The solution is simply to copy the value of
$_ into a local variable that will not get overwritten.
Does this fix any particular bug?  It looks right to me
and makes the code easier to follow, so;
I suspect Merlyn has better explanation, but...

     for (list) {
	...	
     }

loop implicitly localizes $_ and does not share this problem,
which I really appreciate whenever I am writing Perl code, but
often enough I was bitten by scripts that use "while (<$fh>)",
which does not localizes $_, and made hard to spot bugs by
clobbering $_.

I find the patch a good safety measure for any future breakages.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help