Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Capturing regex from map

by Laurent_R (Canon)
on Sep 13, 2013 at 15:04 UTC ( [id://1053955]=note: print w/replies, xml ) Need Help??


in reply to Capturing regex from map

If this works for you, why not, but also take a look at the grep function.

Replies are listed 'Best First'.
Re^2: Capturing regex from map
by Kenosis (Priest) on Sep 13, 2013 at 16:26 UTC

    ...take a look at the grep function...

    Help me understand how grep will pass only the captures from a regex, as map does in this case.

      You are right, grep will not do captures in such a situation. I might not have been clear, but I only mentionned is as an additional useful tool in similar synctactic context, for filtering purpose.

      Having said that you can do something akin to captures in a grep, although it is not very clean. Consider this:

      DB<1> @a = qw (foobar barfoo foobaz, bar, foobor); DB<2> @c = grep {s/fo(ob.).+/$1/} @a; DB<3> x @c 0 'oba' 1 'oba' 2 'obo'

      Not clean, I would not really recommend it, but not impossible.

        Not clean ...

        ... in part, perhaps, because the  @a input array is affected (via aliasing) and winds up 'oba-oba-obo-ed':

        >perl -wMstrict -le "my @a = qw(foobar barfoo foobaz bar foobor); my @c = grep {s/fo(ob.).+/$1/} @a; ;; printf qq{'$_' } for @c; print qq{\n}; printf qq{'$_' } for @a; " 'oba' 'oba' 'obo' 'oba' 'barfoo' 'oba' 'bar' 'obo'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-24 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found