Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Identifiying unique pattern

by inman (Curate)
on Jan 06, 2006 at 12:58 UTC ( [id://521465]=note: print w/replies, xml ) Need Help??


in reply to Identifiying unique pattern

I have interpreted the question as follows: Given a set of file names in an array, find the number of files that share the same alphanumeric prefix so that I know how many files I will be deling with when I use $prefix* as a glob.

I have added to the data to illustrate the point.

my @str= qw(ssg.nal ssg_00.nsr ssg_00.nsn ssg_00.nss xxx_01.txt xxx_0 +3.dat); my %starts; foreach (@str) { #increment the value for the hash element that has the #prefix as a key. $starts{$1}++ if /^([a-zA-Z0-9]+)/; } # print all the prefixes and number of files associated foreach (keys %starts) { print "$_ = $starts{$_}\n"; }
gives
ssg = 4 xxx = 2

Let me know if this is what you had in mind.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://521465]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found