The stupid question is the question not asked | |
PerlMonks |
Re: Capturing regex from mapby Athanasius (Archbishop) |
on Sep 14, 2013 at 04:34 UTC ( [id://1054053]=note: print w/replies, xml ) | Need Help?? |
I agree with the other monks, there’s nothing wrong with using map. However, it is possible to get an equivalent result without map by rearranging and adding the /g and /m modifiers to the regex:
Note that this works because the binding operator puts its left-hand operand into scalar context; and backticks (or qx//) in scalar context return “a single (potentially multi-line) string” (Quote Like Operators). My benckmark tests suggest that this approach may also be more efficient:
Typical output:
Note: Although I’m on Windows, I ended up using Cygwin’s ls -l command because `dir \n` gives an error, and `dir` causes the comparison test to crash. I don’t know what’s going on there. :-( But by all means stick with map if you’re more comfortable with it. Hope that helps,
In Section
Seekers of Perl Wisdom
|
|