donkeykong has asked for the wisdom of the Perl Monks concerning the following question:
I keep getting a '1' as my output. I tried a couple different things but nothing got me any good results, outside of writing a subroutine outside of the hash and calling it as a reference in each value in place of the anonymous subroutines. Any help you guys can provide would be great. Thanksuse strict; my $file = shift @ARGV; open (INPUT, "<$file"); my @ids = qw(1234 2345 3456); my %hash; foreach my $id (@ids) { while (<INPUT>) { $hash{$id} = { headline => sub { return /.*headline: (.*)/ }, byline => sub { return /.*byline: (.*)/}, }; } print $hash{$id}->{byline}->()."\n"; } close INPUT;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: anonymous subroutines assigning regexes to hash keys
by ikegami (Patriarch) on Jul 30, 2009 at 06:13 UTC | |
by donkeykong (Novice) on Jul 30, 2009 at 06:45 UTC | |
by ikegami (Patriarch) on Jul 30, 2009 at 07:06 UTC | |
|
Re: anonymous subroutines assigning regexes to hash keys
by GrandFather (Saint) on Jul 30, 2009 at 05:41 UTC | |
|
Re: anonymous subroutines assigning regexes to hash keys
by pubnoop (Acolyte) on Jul 30, 2009 at 05:50 UTC | |
by donkeykong (Novice) on Jul 30, 2009 at 06:21 UTC |