2008/8/28 Braun Brelin <bbrelin at gmail.com>:
> Hello all,
>> I have a silly Perl question. I'm running an Ubuntu Linux system (8.04),
> with Perl 5.8.8.
>> However, the 'use strict' pragma seems not to be working. I.e. I have the
> following
> Perl script:
>> #!/usr/bin/perl
>> use strict;
>> $a=10;
>> print "a = ",$a,"\n";
>> This should fail miserably with an error about not having $a declared, but,
> unfortunately, it doesn't. It just prints '10'.
>> This isn't my normal machine so I'm not sure how Perl was built, although I
> suspect
> that it isn't anything more than a standard install. perl -V didn't really
> give me any clues. Anything stupidly obvious that I'm missing?
You've declared it as a global variable; 'my' is used to declare a
local variable
#!/usr/bin/perl
use warnings;
use strict;
foo();
sub foo
{
$a=10;
print "a = ",$a,"\n";
}
print $a;
gives:
a = 10
10
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!