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, |
|
|---|