When I run this program on ActivePerl 5.8 on Windows XP, I get a syntax error:
#!C:\Perl\bin\perl.exe
use strict; # enabled
use warnings;
(my $rocks[0], my $rocks[1]) = qw/Hello World/; # Syntax error near '$rocks['
my $rocks[2] = 'Tom'; # Syntax error near '$rocks['
my $rocks[3] = 'Cat'; # Syntax error near '$rocks['
print $rocks[0];
print $rocks[1];
print $rocks[2];
print $rocks[3];
When I used (@) before the name of the array rocks, it worked well.
How do I fix the error above when I used $? Thank you.
my @rocks = qw{Hello World Tom Cat}; # worked well.
Don’t use
myagain and again to declare$rocks[0],$rocks[1]etc.Declare the array once (
@rocks) and use it.The corrected code is something like this: