in reply to anonymous subroutines assigning regexes to hash keys

I don't understand what you're trying to do (it might help if you explain what you intend to do with the hash of hahses once you've got it), but part of your problem is that your loops are in a bit of a mess. You're opening the file, and then for each of the 3 id values you're working though each line of the file (which won't work because the while (<INPUT>) eats the whole file on the first go when $id is 1234, leaving no more input for the other 2 id values). If you want to work through the file 3 times then you have to either close and open it again each time or reset the position with seek().

Each time around the while (<INPUT>) loop, you assign your hash of subs to the same thing, $hash{$id}. With a 100 line file, you'll assign to $hash{$id} 100 times for id 1234, and all but the last one will be lost.

  • Comment on Re: anonymous subroutines assigning regexes to hash keys

Replies are listed 'Best First'.
Re^2: anonymous subroutines assigning regexes to hash keys
by donkeykong (Novice) on Jul 30, 2009 at 06:21 UTC
    I was just making a very abstract version of what I intend on doing. There are going to be several files, and those files come with ID numbers, and the array is going to get automatically populated with the id numbers. So when I go through the file per ID number, it's because it's supposed to go through that entire file per ID number. I can see how this would look wrong based on the abstract version I put up. I was just trying to show what it would do in terms of the actual anonymous subs in the hash of hashes. This is what the inside of a file will look like:
    headline: this is the headline byline: this is the byline (and so on)
    I want to grab all the stuff after the (text):. So the inner hash has the key, which is supposed to have the value of the text after the colon, and was thinking of using an anonymous subroutine to perform a regex and capture just what I wanted. Does this make sense?