in reply to Re: Manipulating the Capture(s) of Regular Expressions
in thread Manipulating the Capture(s) of Regular Expressions

And by extension,
sub transform { my ($ref) = @_; $$ref = 'tripped'; } $text = 'The brown cow jumped over the moon'; if ( $text =~ m/cow\s+(jumped)\s+over/ ) { my $ref = \substr($text, $-[1], $+[1] - $-[1]); transform($ref); } print("$text\n"); # The brown cow tripped over the moon

Update: Expanded the example to be runnable.

Replies are listed 'Best First'.
Re^3: Manipulating the Capture(s) of Regular Expressions
by missingthepoint (Friar) on Jan 12, 2009 at 06:12 UTC

    You two just shot to the top of my mental 'monks who really know Perl and should be listened to' list... :)

    (Edit: well, maybe just after TimToady... :)


    Life is denied by lack of attention,
    whether it be to cleaning windows
    or trying to write a masterpiece...
    -- Nadia Boulanger