Hi, experts,
I have a sample code listed below:
The output is just as expected:
However, if I uncomment the line "use strict", it would not run:
Becuase I have to use "use strict", how can I modify the above code to make it work?
Many thanks!
p.s. I am using linux (ubuntu).
I have a sample code listed below:
Code:
#! /usr/bin/perl
use strict;
print "$0..testing...\n";
my @list = ("a", "b", "c");
print "@list\n";
for(my $i = 0; $i <= $#list ; $i++)
{
for(my $j = 0; $j < 10; $j++)
{
if($i == 0)
{
push @{$list[$i]}, $j;
}
elsif($i == 1)
{
push @{$list[$i]}, $j*2;
}
else
{
push @{$list[$i]}, $j*$j;
}
}
}
foreach my $x (@list)
{
print "\$x = $x, \@{$x} = @{$x}\n";
}
The output is just as expected:
Code:
% ./buildArrayRef.pl
./buildArrayRef.pl..testing...
a b c
$x = a, @{a} = 0 1 2 3 4 5 6 7 8 9
$x = b, @{b} = 0 2 4 6 8 10 12 14 16 18
$x = c, @{c} = 0 1 4 9 16 25 36 49 64 81
However, if I uncomment the line "use strict", it would not run:
Code:
% ./buildArrayRef.pl
./buildArrayRef.pl..testing...
a b c
Can't use string ("a") as an ARRAY ref while "strict refs" in use at ./buildArrayRef.pl line 13.
Becuase I have to use "use strict", how can I modify the above code to make it work?
Many thanks!
p.s. I am using linux (ubuntu).