Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^5: Capturing regex from map

by LanX (Saint)
on Sep 15, 2013 at 18:57 UTC ( [id://1054193]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Capturing regex from map
in thread Capturing regex from map

Well the OP had only one grouping and no /g modifier, such that it does the same thing.

DB<120> @a = map { /(\w*a\w*)/;$1||() } `ls` => ( "babel", "emacs1000", "lanx", "lanx", "seahorse", "man", "Tracker", "virtual", ) DB<121> @a = map { /(\w*a\w*)/ } `ls` => ( "babel", "emacs1000", "lanx", "lanx", "seahorse", "man", "Tracker", "virtual", )

update

FWIW: As already posted my approach to clarify whats happening is

map { my @matches = /.../ ; @matches } LIST or even map { my @matches = /.../ } LIST

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^6: Capturing regex from map
by BrowserUk (Patriarch) on Sep 15, 2013 at 21:13 UTC
    OP had only

    Indeed. Equally, the OP didn't use a void context and a capture variable per Re: Capturing regex from map, but that didn't stop you posting a polemic troll falsely equating the two (despite that you'd already pointed out they were not the same) for no reason other than to have a personal dig.

    The difference between your post and mine, is that mine is intended to point out that the construct -- a regex within the list context of a map assigning to an array -- is very powerful, even beyond the simple use the OP put it to. And that if you take the time to understand why the OPs example works, then the other more powerful uses -- such as the one I demonstrated -- are equally easy to understand and therefore utilise.

    FWIW:

    Not very much. Actually, a negative amount.

    All you did was put the regex into a localised list context by constructing a scoped array; and then convert that array to the list that would have been constructed had you left things alone. That's pointless make-work.

    Anyone who understands that assigning a regex to an array assigns the captures; is equally capable of understanding that the same regex in the list context of a map statement assigned to an array will do the exact same thing.

    You understand it. But you somehow think that other people won't. That you have to clarify the obvious for them by some utterly pointless make-work. You are advocating that 'other people' should dumb down their code, because some other 'other people' might not understand it like you do.

    Suggestion: do not seek to intellectually diminish those 'other people'; seek to educate them.

    If you can understand; and I can understand it; it is a fair bet that with just a little exposure; they will understand it too. It's neither that complicated, nor undocumented.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Anyone who understands that assigning a regex to an array assigns the captures; is equally capable of understanding that the same regex in the list context of a map statement assigned to an array will do the exact same thing.

      Understanding either or both does not make the OP's code a shining beacon of clarity, IMO.

        Understanding either or both does not make the OP's code a shining beacon of clarity,

        If you understand it, how can it possibly be unclear?

        This is exactly the same ridiculous argument as is proffered here so often.

        Yes. Of course, *I* understand it, but other people might not, so therefore, it is not "a beacon of clarity".

        And if you do not understand it; just say that. Then we can point you to the documentation; and perhaps offer further examples, or a break down of why and how it works, to help you reach the understanding you are lacking.

        Do not advocate the dumbing down of other peoples code, simply because you don't understand it; or you fear that others might not.

        The key to understanding is not pretending the (in this case, hardly) complicated stuff doesn't exist; it is education.

        Don't seek to cover it up, or hide in in a box labeled "wizards only"; explain it.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-28 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found