Just a quick question on the need of "my" 
http://perldoc.perl.org/functions/my.html

Was using an example from the beginning perl text in the example he
gave he wasn't using strict but i have it on to all scripts by
default.

For this example. the first two assignments work okay, but then at $c
if I do not declare my local then I get an error. $d also requires
that it be assigned using my, though it is directly the same as $b, my
assumption here is that $d required explicit assignment as it used the
explicitly assigned variable $c (could be wrong).

Why from $c was "my" required?
NB I am using 5.14.1

#!/usr/bin/perl -w
# vars3.pl --- Assignment of vars using strict
# Author: sayth <sayth@sayth>
# Created: 05 Sep 2011
# Version: 0.01

use warnings;
use strict;

$a = 6*9;
print "six times 9 is ", $a, "\n";
$b = $a + 3;
print "plus three is ", $b,"\n";
my $c = $b/3;
print "Divided by 3 is ", $c, "\n";
my $d = $c + 1;
print "plus one is ", $d, "\n";


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to