in reply to Re: Question on Regular Expression
in thread Question on Regular Expression

If I understand the documentation, you can remove eval from there, as it's useless for qr{}.

Well, as far as I can tell, the code the OP posted doesn't make use of the eval feature at all , the code section is a literal

literal

$ perl -E " $_ = 123; m/\d(?{ warn pos })/" 1 at (re_eval 5) line 1. $ perl -E " no re qw/eval/; $_ = 123; m/\d(?{ warn pos })/" 1 at (re_eval 5) line 1. $ perl -E " $_ = 123; $f = qr/\d(?{ warn pos })/; m/$f/;" 1 at (re_eval 5) line 1. $ perl -E " no re qw/eval/; $_ = 123; $f = qr/\d(?{ warn pos })/; m/$f +/;" 1 at (re_eval 5) line 1.

variable aka "dynamic" aka it throws error :)

$ perl -E " $_ = 123; $f = '(?{ warn pos })'; m/\d$f/; " Eval-group not allowed at runtime, use re 'eval' in regex m/\d(?{ warn + pos })/ at -e line 1. $ perl -E " $_ = 123; $f = '(?{ warn pos })'; $g = qr/\d$f/; m/$g/" Eval-group not allowed at runtime, use re 'eval' in regex m/\d(?{ warn + pos })/ at -e line 1.

I believe whatever the OPs real code, he got this error message so he added the "solution"

I also believe there is no need for any of this stuff :) if all the OP is doing is building a data structure, simply match in a loop and use %+ or use Regexp::Grammars

Replies are listed 'Best First'.
Re^3: Question on Regular Expression
by sjain (Initiate) on Dec 27, 2014 at 14:17 UTC

    Can you please let me know how to make use of %+ so to match in a loop even if the submatch in a pattern string fails?

      Can you please let me know how to make use of %+ so to match in a loop even if the submatch in a pattern string fails?

      um, \d always fails :)

      #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; my $cool = qr/ (?<key> \s* (?<key2>\w+) \s* (?<keyQ>\w+) \s* (?<NEVER>\d*) ) /x; my $beans = 'castor cocoa coffee pinto navy Mayocoba'; while( $beans =~ m{$cool}g ){ dd( \%+ ); } __END__ { # tied Tie::Hash::NamedCapture key => "castor cocoa ", key2 => "castor", keyQ => "cocoa", NEVER => "", } { # tied Tie::Hash::NamedCapture key => "coffee pinto ", key2 => "coffee", keyQ => "pinto", NEVER => "", } { # tied Tie::Hash::NamedCapture key => "navy Mayocoba", key2 => "navy", keyQ => "Mayocoba", NEVER => "", }

        Sorry I couldnt use 'dd' as I got the below error

        Can't locate Data/Dump.pm in @INC (@INC contains: /home/samanth/.cpan/build/File-Monitor-1.00-9nE6lN/lib /home/samanth/.cpan/build/File-Monitor-1.00-9nE6lN/lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./s5.pl line 5. BEGIN failed--compilation aborted at ./s5.pl line 5.

        if You could provide sample without 'dd' would be muchappreciated.