Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 555 forks source link

Variable suicide considered out of fashion #708

Closed p5pRT closed 20 years ago

p5pRT commented 25 years ago

Migrated from rt.perl.org#1610 (status was 'resolved')

Searchable as RT1610$

p5pRT commented 25 years ago

From mjtg@cus.cam.ac.uk

=head2 What is variable suicide and how can I prevent it?

is still there? It refers to a bug which was mended well before perl5.004. And documenting known bugs in the FAQ is a slightly odd thing to do. And it certainly hasn't qualified as a _F_AQ for a very long time. Or even as an IAQ.

I suggest its removal.

Mike Guy

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

M.J.T. Guy wonders​:

Is there any good reason why the entry in perlfaq7

=head2 What is variable suicide and how can I prevent it?

is still there? It refers to a bug which was mended well before perl5.004. And documenting known bugs in the FAQ is a slightly odd thing to do. And it certainly hasn't qualified as a _F_AQ for a very long time. Or even as an IAQ.

I suggest its removal.

Inline Patch ```diff --- perlfaq.orig Tue Dec 19 14:36:08 2000 +++ perlfaq.pod Tue Dec 19 14:37:23 2000 @@ -496,8 +496,6 @@ =item * What's a closure? -=item * What is variable suicide and how can I prevent it? - =item * How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}? =item * How do I create a static variable? @@ -761,6 +759,10 @@ =head1 Changes =over 4 + +=item 19/December/2000 + +Removed variable suicide question. =item 1/November/2000 --- perlfaq7.orig Tue Dec 19 14:36:17 2000 +++ perlfaq7.pod Tue Dec 19 14:37:42 2000 @@ -322,27 +322,6 @@ hypothetical timeout() function to access the lexical variable $line back in its caller's scope. -=head2 What is variable suicide and how can I prevent it? - -Variable suicide is when you (temporarily or permanently) lose the -value of a variable. It is caused by scoping through my() and local() -interacting with either closures or aliased foreach() iterator -variables and subroutine arguments. It used to be easy to -inadvertently lose a variable's value this way, but now it's much -harder. Take this code: - - my $f = "foo"; - sub T { - while ($i++ < 3) { my $f = $f; $f .= "bar"; print $f, "\n" } - } - T; - print "Finally $f\n"; - -The $f that has "bar" added to it three times should be a new C<$f> -(C should create a new local variable each time through the loop). -It isn't, however. This was a bug, now fixed in the latest releases -(tested against 5.004_05, 5.005_03, and 5.005_56). - =head2 How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}? With the exception of regexes, you need to pass references to these ```