Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Capturing regex from map

by trippledubs (Deacon)
on Sep 13, 2013 at 17:11 UTC ( [id://1053970]=note: print w/replies, xml ) Need Help??


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

Well possibly I was thinking that it has only worked "so far" and that some landmine is potentially waiting, since I haven't seen that construct elsewhere. I'm not exposed to a lot of code though so I usually suspect any original thought is either not original or wrong for some reason I haven't thought of. I usually see something like
my ($match_1,$match_2) = ($string =~ /(.*):(.*)/) // And in my own scripts I'm using constructs like my ($wanted_service) = (map { /^online.*svc:(.*?):/ } `svcs`)[15];
Someone asked me, what is the best way to do x, I reach for the handy regex mapper, but I'm not sure it is the best. In sum: lack of confidence and the competitive drive for perfection. AND to a smaller degree, I want more xp. Why did you wonder why I wondered? This might go on all day, maybe I'll level up! :)

Replies are listed 'Best First'.
Re^3: Capturing regex from map
by BrowserUk (Patriarch) on Sep 13, 2013 at 17:34 UTC
    Why did you wonder why I wondered?

    Because most times when this kind of question -- someone second guessing a piece of working code -- comes up, there is usually some clue, either in the post, or in the history of this place, to indicate what the fear that underlies the question is.

    With your question I detect nothing that indicates either a commonly frowned upon, but otherwise workable construct -- as we often see with map in a scalar or void context for example -- nor anything in your post to indicate the basis of your doubts.

    I cannot see any reason not to use the construct for those occasions when it does the required task. It is concise and to my eyes clear. But, there is the possibility that I'm missing something, hence I wanted to know more ...


    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.
      > It is concise and to my eyes clear.

      well, as you can see from some answers it's not clear for everybody.

      you are using the fact that 'm//' in list context returns a list of the grouped matches (if any).

      (w/o grouping it returns 1 for true matches)

      If you are using this idiom very often you might want to document it for other maintainers...

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        you are using

        I'm not using anything, but if I were called upon to maintain the OPs code; *I* would not have a problem with it.

        Try addressing your pedantry to the OP. He might be interested.


        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://1053970]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-16 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found