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! :) | [reply] [d/l] |
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.
| [reply] |
> 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)
| [reply] |