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

Re^2: Shorthand for /^\s*abc\s*$/ ?

by Laurent_R (Canon)
on Oct 11, 2015 at 16:38 UTC ( [id://1144437]=note: print w/replies, xml ) Need Help??


in reply to Re: Shorthand for /^\s*abc\s*$/ ?
in thread Shorthand for /^\s*abc\s*$/ ?

I like this approach, AppleFritter, but it could perhaps be made slightly simpler (or maybe not simpler but only more concise):
use strict; use warnings; use 5.014; my %interesting; for (qw/ abc cmc uep a{3}/) { $interesting{$_} = sub { say "got '$_'!"}; } # process data and apply tests for (@ARGV) { foreach my $test (keys %interesting) { /^\s*$test\s*$/ and $interesting{$test}->(); } }
Running it:
$ perl regexes.pl abc uep cmc aaa foo bar got 'abc'! got 'uep'! got 'cmc'! got 'aaa'!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-18 18:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found