[Chicago-talk] Using a hash in a regex

David H. Adler dha at panix.com
Thu Jul 13 14:17:01 PDT 2006

On Thu, Jul 13, 2006 at 04:01:50PM -0500, Jay Strauss wrote:
> Just to be clear.  I have a bunch of files in a directory.  The filename
> has within it (somewhere) a key(word) like: "income".  I need to
> sequence these files in a specified order.  So I use a hash like:
> %h = (... income=> 13 ...); # the ... are not Perl
> Then I glob my directory and get a filename like:
> $filename = "bank statements used for income.pdf"
> So I change the filename to be:
> "13.bank statements used for income.pdf"
> And then I'm onto the next file

So it looks like what you really want is something like

	$match = join '|', @matchwords;
	    for (@files) {
	    next unless $word = /($match)/;

I'm, of course, assuming a lot of things here, like that there will only
be one match per file name, but is that the kind of thing you're looking


David H. Adler - <dha at panix.com> - http://www.panix.com/~dha/
No sign of any external injury, but I'm afraid he's very dead.
        - Captain Scarlet

More information about the Chicago-talk mailing list