[win32] merge change#897 from maintbranch
[p5sagit/p5-mst-13.2.git] / pod / perlfaq7.pod
index a1d60f8..d62ee36 100644 (file)
@@ -1,6 +1,6 @@
 =head1 NAME
 
-perlfaq7 - Perl Language Issues ($Revision: 1.16 $, $Date: 1997/03/19 17:25:23 $)
+perlfaq7 - Perl Language Issues ($Revision: 1.18 $, $Date: 1997/04/24 22:44:14 $)
 
 =head1 DESCRIPTION
 
@@ -169,7 +169,7 @@ own module.  Make sure to change the names appropriately.
 
        # if using RCS/CVS, this next line may be preferred,
        # but beware two-digit versions.
-       $VERSION = do{my@r=q$Revision: 1.16 $=~/\d+/g;sprintf '%d.'.'%02d'x$#r,@r};
+       $VERSION = do{my@r=q$Revision: 1.18 $=~/\d+/g;sprintf '%d.'.'%02d'x$#r,@r};
 
        @ISA         = qw(Exporter);
        @EXPORT      = qw(&func1 &func2 &func3);
@@ -298,6 +298,26 @@ E<lt>STDINE<gt>'>, there would have been no way for the 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() interator
+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<my $f> should create a new local variable each time through the
+loop).  It isn't, however.  This is a bug, and will be fixed.
+
 =head2 How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regexp}?
 
 With the exception of regexps, you need to pass references to these
@@ -339,9 +359,9 @@ IO::File modules, both part of the standard Perl distribution.
 
 To pass regexps around, you'll need to either use one of the highly
 experimental regular expression modules from CPAN (Nick Ing-Simmons's
-Regexp or Ilya Zakharevich's Devel::Regexp), pass around strings and
-use an exception-trapping eval, or else be very, very clever.  Here's
-an example of how to pass in a string to be regexp compared:
+Regexp or Ilya Zakharevich's Devel::Regexp), pass around strings
+and use an exception-trapping eval, or else be be very, very clever.
+Here's an example of how to pass in a string to be regexp compared:
 
     sub compare($$) {
         my ($val1, $regexp) = @_;
@@ -539,7 +559,7 @@ Why do you want to do that? :-)
 If you want to override a predefined function, such as open(),
 then you'll have to import the new definition from a different
 module.  See L<perlsub/"Overriding Builtin Functions">.  There's
-also an example in L<perltoot/"Class::Struct">.
+also an example in L<perltoot/"Class::Template">.
 
 If you want to overload a Perl operator, such as C<+> or C<**>,
 then you'll want to use the C<use overload> pragma, documented
@@ -576,7 +596,7 @@ how best to do this, so he left it out, even though it's been on the
 wish list since perl1.
 
 Here's a simple example of a switch based on pattern matching.  We'll
-do a multiway conditional based on the type of reference stored in
+do a multi-way conditional based on the type of reference stored in
 $whatchamacallit:
 
     SWITCH:
@@ -649,7 +669,7 @@ before Perl has seen that such a package exists.  It's wisest to make
 sure your packages are all defined before you start using them, which
 will be taken care of if you use the C<use> statement instead of
 C<require>.  If not, make sure to use arrow notation (eg,
-C<Guru->find("Samy")>) instead.  Object notation is explained in
+C<Guru-E<gt>find("Samy")>) instead.  Object notation is explained in
 L<perlobj>.
 
 =head2 How can I find out my current package?
@@ -669,6 +689,28 @@ not necessarily the same as the one in which you were compiled):
        warn "called me from a $class object";
     }
 
+=head2 How can I comment out a large block of perl code?
+
+Use embedded POD to discard it:
+
+    # program is here
+
+    =for nobody
+    This paragraph is commented out
+
+    # program continues
+
+    =begin comment text
+
+    all of this stuff
+
+    here will be ignored
+    by everyone
+
+    =end comment text
+
+    =cut
+
 =head1 AUTHOR AND COPYRIGHT
 
 Copyright (c) 1997 Tom Christiansen and Nathan Torkington.