Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl requires explicit package name

Tags:

perl

#!/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?).

like image 361
KAKAK Avatar asked Apr 25 '13 15:04

KAKAK


1 Answers

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){

like image 117
Quentin Avatar answered Oct 01 '22 12:10

Quentin