Hi Monks,
I've been in a position of Linux sysadmin for the past 4 years and with the exception of very (very!) light bash use (I use "use" as opposed to scripting since most of what I write fits on a single (albeit very long) line. Not to say that it isn't useful\) I don't really do any scripting. I figured it was time to learn, so I picked up "Learning Perl - 6th edition" from my local bookstore yesterday and I have to say it's been a delight so far!
Question:
My version of perl is 5.14.2. I'm reading about the use of private persistent variables using the "state" keyword. The book introduces those with the "use 5.010;" pragma. If I don't declare "use 5.010;", the state variables doesn't work as expected and I get:
Can't call method "state" on an undefined value at ./state_var.pl line 7.
Code:
#!/home/erikg/bin/perl
#use 5.010;
&marine;
sub marine {
my $counter = 0;
while ($counter < 10) {
state $n = 0;
$n += 1;
print "\n$n";
$counter++;
}
}
But as soon as I remove the comment in front of use, it works fine. Although I understand "use strict;" and "use warning;" are ways of turning on/off strict/warning use, I was under the impression "use 5.XXX;" was a way of verifying the Perl interpreter was at least up to that version or better. I guess not...
Question: If I have "use 5.010;" at the beginning of my code, does that mean any features in Perl newer than 5.010 will be unavailable?
TIA