Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Iterating through Hashes in Files

by jedikaiti (Friar)
on Mar 29, 2010 at 20:17 UTC ( #831697=perlquestion: print w/ replies, xml ) Need Help??
jedikaiti has asked for the wisdom of the Perl Monks concerning the following question:

I have a directory full of files, each containing a hash with the same name as the file. (i.e., a file called 'data1.pm' contains a hash called '%data1'.) I need to iterate through some of those files, and mess with the data in the hashes. All the files I need have names in the format *Cmd.pm) (clockCmd.pm, chairCmd.pm, that sort of thing).

So, what's the simplest way to do this? All the file names are known, so I could just use an array holding all the file/hash names and run through that, but I am wondering if there's something simpler or more elegant.

Danke!

Kaiti
Swiss Army Nerd

Comment on Iterating through Hashes in Files
Re: Iterating through Hashes in Files
by ssandv (Hermit) on Mar 29, 2010 at 20:23 UTC

    Angle brackets, in addition to being shorthand for readline, also can be used to perform globbing (wildcard expansion). So, <*Cmd.pm> will return a list of all the filenames of the format you describe. Ultimately you'll have to "run through" a list/array at some point, but that allows you to get the list dynamically instead of hardcoding it (provided that every file in the directory that matches the wildcard is a file you want to look in).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://831697]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2014-09-30 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (381 votes), past polls