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

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?

Replies are listed 'Best First'.
Re^4: Question on Regular Expression
by Anonymous Monk on Dec 28, 2014 at 06:03 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?

    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.

        Either install the missing module
        cpan Data::Dump

        or replace dd with

        print Dumper

        and use Data::Dumper instead of Data::Dump.

        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ