Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by Athanasius (Archbishop)
on Oct 11, 2015 at 13:13 UTC ( [id://1144425]=note: print w/replies, xml ) Need Help??


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

I like AppleFritter’s approach. But, in the spirit of TMTOWTDI, here’s another, which builds the required regex via a subroutine call:

#! perl use strict; use warnings; my %searches = ( bar => " bar \n\n", foo => " foo c \n", ); for (sort keys %searches) { print "$_: ", $searches{$_} =~ re($_) ? 'match' : 'no match', "\n" +; } sub re { qr{ ^ \s* $_[0] \s* $ }x; }

Output:

23:06 >perl 1402_SoPW.pl bar: match foo: no match 23:06 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-19 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found