Is it just me, or does anyone out there notice that the example subroutine
on pg. 57 of "Learning Perl" (Third Edition) doesn't work, as presented?
When written like:
----------------snip------------------
#!/usr/bin/perl -w
use strict;
sub marine {
my $n += 1; # Global variable $n
print "Hello, sailor number $n!\n";
}
&marine;
&marine;
&marine;
&marine;
----------------snip------------------
STDOUT gets:
Hello, sailor number 1!
Hello, sailor number 1!
Hello, sailor number 1!
Hello, sailor number 1!
But, when written like:
----------------snip------------------
#!/usr/bin/perl -w
use strict;
my $n = 1;
sub marine {
print "Hello, sailor number $n!\n";
$n += 1; # Global variable $n
}
&marine;
&marine;
&marine;
&marine;
----------------snip------------------
STDOUT gets:
Hello, sailor number 1!
Hello, sailor number 2!
Hello, sailor number 3!
Hello, sailor number 4!
...like it's supposed to. Am I missing some key information here?? Or, is
the book just a bit unclear??
Ron
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]