Perl syntax

John Vetterli jvetterli-zC6tqtfhjqE at public.gmane.org
Mon May 30 14:15:18 UTC 2005


On Mon, 30 May 2005, John Wildberger wrote:
> #! /usr/bin/perl -w
> use strict;
> while (<>){
>    $count{$ARGV}++;
> }
> foreach $file (sort keys %count){
>    print "$file has $count{$file}  lines\n";
> }

What I usually do is introduce all variables with "my":
use strict;
my %count = ();
while (<>){
     $count{$ARGV}++;
}
foreach my $file (sort keys %count){
     print "$file has $count{$file}  lines\n";
}

This should keep perl happy.

HTH
JV


> When executed it gives the following error messages:
> [john]: 09:46 AM  [~/perl]
> $ ./urc2_1.pl urc2_1.pl
> Global symbol "%count" requires explicit package name at ./urc2_1.pl line 4.
> Global symbol "$file" requires explicit package name at ./urc2_1.pl line 6.
> Global symbol "%count" requires explicit package name at ./urc2_1.pl line 6.
> Global symbol "$file" requires explicit package name at ./urc2_1.pl line 7.
> Global symbol "%count" requires explicit package name at ./urc2_1.pl line 7.
> Global symbol "$file" requires explicit package name at ./urc2_1.pl line 7.
> Execution of ./urc2_1.pl aborted due to compilation errors.
>
> What changes to the program will I have to make to correct this?
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list