in reply to Re: Re: Re: Re: What's the best way to do a pattern search like this?
in thread What's the best way to do a pattern search like this?
As noted by MeowChow the devil is in the details:
#!/usr/bin/perl -w use strict; my %codes; open (FILE, "file.txt") || die "Can't open data file, perl says $!"; while (<FILE>) { my @array_codes = /[A-Za-z0-9]+/g; foreach my $code_key (@array_codes) { $codes{$code_key}++; } } print "$_\t$codes{$_}\n" for sort keys %codes;
This will get groups of chars that match A-Za-z0-9 only and then prints out the sorted hash. I have added the $! var in the die which contains Perl's error message and sort the keys. I have added us strict, -w and the my declarations. Also note that printf was a typo. I meant print.
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|