This can be made slightly less ugly by
if it's really necessary to have named backreferences in the regex via a hash.c:\@Work\Perl>perl -wMstrict -le "use Data::Dumper qw(Dumper); ;; print qq{perl version $]}; ;; q(abc de f abcdef) =~ m/ ( (\w{3}) (?{ $+{x} = $^N; }) .* (??{ $+{x}; }) ) /x and print qq{\$1 '$1' \n}, Dumper \%+; " perl version 5.008009 $1 'abc de f abc' $VAR1 = { 'x' => 'abc' };
Otherwise, I'm not sure I see its advantage over something like
or perhaps likec:\@Work\Perl>perl -wMstrict -le "print qq{perl version $]}; ;; q(abc de f abcdef) =~ m/ ( (\w{3}) .* \2 ) /x and print qq{\$1 '$1'}; " perl version 5.008009 $1 'abc de f abc'
c:\@Work\Perl>perl -wMstrict -le "print qq{perl version $]}; ;; my $match = my ($whole, $first_part) = q(abc de f abcdef) =~ m/ ( (\w{3}) .* \2 ) /x ;; print qq{first part '$first_part' whole '$whole'} if $match; " perl version 5.008009 first part 'abc' whole 'abc de f abc'
Give a man a fish: <%-{-{-{-<
In reply to Re^2: Do a named regex group in 5.8?
by AnomalousMonk
in thread Do a named regex group in 5.8?
by crusty_collins
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |