newbie01 perl wrote:
Hi all,
If I declare a variable x1 outside of the sub that makes it global, right?
Now the question is can I have the same variable x1 as a local variable of a
sub, i.e. will the following work?
$x1 = "cat";
sub sample()
{
my $x1="dog";
...
...
}
Just trying to work out some guidelines on using variables, i.e. using
local, my or global and some naming converntion stuff ...
Is there some good links on such guidelines?
You should write a small script to test it yourself.
#!/usr/bin/perl
use strict;
use warnings;
my $x1 = "cat";
print "My favourite pet is a $x1\n";
{
print "My favourite pet is a $x1\n";
my $x1 = "dog";
print "My favourite pet is a $x1\n";
}
print "My favourite pet is a $x1\n";
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
I like Perl; it's the only language where you can bless your
thingy.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/