Perl syntax
dan sinclair
zero-zgL5Owk5LsjZLAS6AT9qEw at public.gmane.org
Mon May 30 14:12:49 UTC 2005
#! /usr/bin/perl -w
use strict;
my %count = ();
while (<>){
$count{$ARGV}++;
}
foreach my $file (sort keys %count){
print "$file has $count{$file} lines\n";
}
dan
> In the recent thread on this subject the 'use strict' pragma was very strongly
> suggessted.
> Here is a very simple program urc2_1.pl:
>
> #! /usr/bin/perl -w
> use strict;
> while (<>){
> $count{$ARGV}++;
> }
> foreach $file (sort keys %count){
> print "$file has $count{$file} lines\n";
> }
>
> 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.
>
> Without the 'use strict' pragma it executes without errors like this:
>
> [john]: 09:44 AM [~/perl]
> $ ./urc2_1.pl urc2_1.pl
> urc2_1.pl has 9 lines
>
> What changes to the program will I have to make to correct this?
> John
> --
> 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
>
--
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