Reputation: 899
#!/usr/bin/perl
# countlines2.pl by Bill Weinman <http://bw.org/contact/>
# Copyright (c) 2010 The BearHeart Group, LLC
use strict;
use warnings;
sub main {
my @values = (43,123,5,89,1,76);
my @values1 = sort(@values);
foreach $value(@values1){
print "$value\n";
}
}
Errors -
"Global symbol "$value" requires explicit package name at task2.txt line 12
"Global symbol "$value" requires explicit package name at task2.txt line 13
I am beginner in perl so i am having the above errors. Also please do tell me how the perl sorts the numbers by default(e.g. what the sort(@values) will result in?).
Upvotes: 7
Views: 18557
Reputation: 943143
You might find it helpful to add use diagnostics;
which would give you this additional information:
(F) You've said "use strict" or "use strict vars", which indicates that all variables must either be lexically scoped (using "my" or "state"), declared beforehand using "our", or explicitly qualified to say which package the global variable is in (using "::").
foreach $value(@values1){
should be foreach my $value(@values1){
Upvotes: 17
Reputation: 10572
The error is because you are not declaring $value
:
foreach my $value(@values1){
print "$value\n";
}
The sorting documentation can be found here: http://perldoc.perl.org/functions/sort.html.
Upvotes: 11