in reply to How to do script to separate name and email domain ?
Note that your source of things can be anything: the keys of a hash, the lines read from a filehandle, items in an array. This is a good general pattern of scan-and-count-unique that wil help in a lot of contexts. Sorting into frequency of ocurrence, etc. left as an exercise to the reader.my %classification; # Scan and "bucket" the items for each $thing (@source_of_things) { # If the thing needs to be transformed, truncated, or pattern-matche +d, # do that here to get the unique part you're interested in. $classification{$unique_part_of_thing}++; } # Analyze and report. foreach $item (keys %classification) { print "$item found $classification{$item} time", ($classification{$item}==1 ? '' : "s"), "\n"; # Or whatever you need to do with each unique item and the number of # times it was found. }
|
|---|