David Wright wrote: > > > > I'm trying to count the recurrence of lines in a file. This works > > how i want but first it prints "Use of uninitialized,... " - see below. > > I know i'm probably not supposed to use a hash like this but it does > > work. I either need another "error free" way to do this or a fix. I > > have figures out that the error message seems to be saying that it > > can't add the eof() value to the hash, what is that value, i have tried > > many different variations,... Thanks in advance. > > > > 1 #!/usr/bin/perl -w > > 2 use strict; > > 3 my (@storeList, $file); > > 4 > > 5 print ("Which file do you want to check for dups?\n"); > > 6 chomp($file=<STDIN>); > > 7 open(FILEIN, "<$file") || die "Can't open dude: $!"; > > 8 @storeList=<FILEIN>; > > 9 recordDups(@storeList);
You might want to think about passing a reference to the array instead of the whole array. > > 11 sub recordDups { > > 12 my @array = @_; > > 13 my ($dup, %saveNum); > > 14 foreach $dup (@array){ > > 15 $saveNum{$dup} =$saveNum{$dup}+1; The reason you are getting the warnings is because of $saveNum{$dup} on the right hand side of the expression. Use either: $saveNum{$dup}++; or: $saveNum{$dup} += 1; > > 16 } > > 17 > > 18 foreach $dup(keys(%saveNum)){ > > 19 print "$saveNum{$dup} copies(s) of: $dup"; > > 20 } > > 21 > > 22 } > > > > The output of a random file: > > > > [snip output] John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]