Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Question on Regular Expression

by sjain (Initiate)
on Dec 27, 2014 at 14:17 UTC ( [id://1111457]=note: print w/replies, xml ) Need Help??


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.

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-23 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found