Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Personally I get sick of all the regexp questions on here but this is one I don't ever seeing before or heard of being done.

I call a regexp with a hash:
$f->do_this({ '.*\.doc$' => [qw/delete_me 1/], '.*\.xls$' => [qw/copy_to C:\test/], 'dean' => [qw/return_this rel_file|stat_8/], 'F:/dean/ => ['mirror_to', 'C:\test'] });
... which is compiles into a search string in the object using the method ...
sub do_this { my ($self, $args) = @_; my %hash = %{$args}; while (my ($d, $r) = each (%hash)) { $self->{actions}{$d} = $r; #print "D: $d\nR: @$r\n"; } my $string = undef; map {$string .= $_ . "|"} keys(%{$args}); $string =~ s/\|$//; ##remove the last pipe symbol $string = qr/$string/i; $self->{find} = $string; ## this is the string to match files a +gainst #print $self->{find}; }
.... now when I do a pattern match against it (which by the way works perfectly!) ... I then have a problem ... I know $& returns the matched string ... but I need what PATTERN WAS USED to match against the string. How?

This is the code where I do the matching and want to return the PATTERN USED.
if (/$self->{find}/) { my $this = $&; my $matched = ## find pattern used here process($self, $_, $dir, $matched); }
Reasons is I then need to process the original hash (shown at the top of this) using the PATTERN USED as the key to the hash for what entry was found. How can I do this?

Dean
The Funkster of Mirth
Programming these days takes more than a lone avenger with a compiler. - sam
RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers

In reply to Returning regexp pattern that was used to match by crabbdean

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (13)
    As of 2015-07-01 19:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (17 votes), past polls