Perl requires an explicit package name

#!/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 start in perl, so I get the above errors. Also, please tell me how perl sorts default numbers (for example, what will result in sorting (@values)?).

+5
source share
2 answers

You may find it helpful to add use diagnostics;one that will provide you with additional information:

(F) You said “use strict” or “use strict vars”, which indicates that all variables should be either lexically covered (using “my” or “state”), previously declared using “ours” or explicitly qualified to say what package the global variable is in (using "::").

foreach $value(@values1){ foreach my $value(@values1){

+14

, $value:

foreach my $value(@values1){
    print "$value\n";
  }

: http://perldoc.perl.org/functions/sort.html.

+11

All Articles