in reply to anonymous subroutines assigning regexes to hash keys

Others have pointed out other problems with your code, but your actual question has gone unanswered. (Well, I answered it when you asked in the CB earlier, but I guess you missed it.)

You're calling the anonymous sub in scalar context, which results in the match being evaluated in scalar context, and m// in scalar context returns whether a match occurred or not.

You need to call m// in list context or use $1 to access what the match captured. Here are two ways to fix your anon subs to return the desired value:

sub { ( /.*headline: (.*)/ )[0] },
sub { /.*headline: (.*)/ && $1 },

Replies are listed 'Best First'.
Re^2: anonymous subroutines assigning regexes to hash keys
by donkeykong (Novice) on Jul 30, 2009 at 06:45 UTC
    Thanks so much for responding to the actual question. I just wrote an abstract piece of code, not the actual code that I was using. I tried both of the solutions though, and neither brought back a result. Any ideas? I appreciate it.

      It's impossible for those expressions to return nothing back.

      It's impossible an expression to nothing back in scalar context.

      If they return undef, then the pattern didn't match. Make sure $_ contains what you think it should.

      If they return a zero-length string, it's because that's what they successfully matched.