Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Iterating through Hashes in Files

by jedikaiti (Hermit)
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

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2018-05-27 10:58 GMT
Find Nodes?
    Voting Booth?