PERL @ (at sign) and ARRAY

commandline session

$cat array.pl
#!/usr/bin/perl
use strict;
use warnings;


my @colors = ("red","green","blue");
print "@colors";
print "n";
$perl array.pl
red green blue
$vim array.pl
$cat array.pl
#!/usr/bin/perl
use strict;
use warnings;


my @colors = ("red","green","blue");
print "@colors";
print "n";
print $color[0];
print "n";

$perl array.pl
Global symbol "@color" requires explicit package name at array.pl line 9.
Execution of array.pl aborted due to compilation errors.
$vim array.pl
$cat array.pl
#!/usr/bin/perl
use strict;
use warnings;


my @colors = ("red","green","blue");
print "@colors";
print "n";
print $colors[0];
print "n";

$perl array.pl
red green blue
red
$

Leave a comment

Your email address will not be published. Required fields are marked *