Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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 '' 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 * (,, 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.


Swiss Army Nerd

Comment on Iterating through Hashes in Files
Replies are listed 'Best First'.
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, <*> 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?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2015-10-09 18:42 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (250 votes), past polls