Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: Condensing a grep into a sort

by ikegami (Patriarch)
on Jun 09, 2009 at 19:40 UTC ( [id://770072]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Condensing a grep into a sort
in thread Condensing a grep into a sort

I was wondering really, if it was possible to have a regular expression return 'null', in list context, and to have sort somehow not add the null to the sorted list. Does this make sense?

I presume you mean the match operator when you say regular expression.

And yes, that's possible. The match operator returns an empty list in list context for a failed match.

$ perl -le'print for map /^foo(.*)/, @ARGV' foobar foobaz dodo bar baz

The problem isn't what it returns when the match fails, it's what it returns when the match succeeds. You want it to return both the number and the entire string as one value, and that's not going to happen.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-03-29 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found