Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Best way to match items in an array

by stefp (Vicar)
on Dec 07, 2002 at 06:29 UTC ( [id://218227]=note: print w/replies, xml ) Need Help??


in reply to Best way to match items in an array

The first pass gathers the filenames in %file. The second pass handles the files suffix per suffix if an handler of the form handle_XXX is defined for the suffix XXX. Note that you can add new handlers without touching the logic.
#! /usr/bin/perl use strict; my %file; # hash of filenames arrays keyed by suffix # first pass for (<*>) { push @{$file{$2}}, $_ if /(.*\.(.*))/; } # second pass for my $suffix (sort keys %file) { no strict 'refs'; next unless defined &{"handle_$suffix"}; &{"handle_$suffix"}($_) for sort @{$file{$suffix}} } # process the file with suffix '.cpp' sub handle_cpp { print "$_[0]\n"; }

-- stefp

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2025-05-23 02:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.