Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: anonymous subroutines assigning regexes to hash keys

by ikegami (Patriarch)
on Jul 30, 2009 at 06:13 UTC ( [id://784499]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://784499]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-21 03:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found