in reply to Hash to count characters
open (DAT, "@ARGV");
"@ARGV" is short for join( $", @ARGV ). If you just want the first argument from the command line then use $ARGV[0] instead. You should really be using the three argument form of open and you should always verify that the file opened correctly, so:
open mt $DAT, '<', $ARGV[ 0 ] or die "Cannot open '$ARGV[0]' $ +!";
while ($line = <DAT>){ do (@word = split (/\W/, $line)); foreach $word (keys %charCount){ do (@letter = split (/\w+/, $word); $letter = (keys %charcount)} if ($charCount){$char}){ $charCount{$char}++; }else { $charCount{$char}=1; }
Since you say that you only want letters you need something like this:
my %charCount; while ( my $line = <$DAT> ) { my @letters = $line =~ /[a-zA-Z]/g; foreach my $char ( @letters ) { $charCount{ $char }++; } } foreach my $char ( keys %charCount ) { print "$char => $charCount{$char}\n"; }
close(DAT, "@ARGV");
close only accepts one argument, the filehandle that was previously opened.
close $DAT;
|
|---|