Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: How do I pass $1 to s///?

by Anonymous Monk
on Jan 06, 2006 at 17:07 UTC ( [id://521548]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I pass $1 to s///?
in thread How do I pass $1 to s///?

Ah, thankyou! The only problem is that I want to pass a much more complicated string in than "fish $1"... What do you mean by a templating system? Can you point me at a webpage or something? Thanks for the replies BTW! It's most appreciated! (You monks reply fast too! :)

Replies are listed 'Best First'.
Re^3: How do I pass $1 to s///?
by ikegami (Patriarch) on Jan 06, 2006 at 17:23 UTC

    You can pass any Perl source code in the above snippet (which is why it's potentially dangerous).

    One templating system would be the Template Toolkit.

    use Template; sub foo { my $template = Template->new(); (my $text = $_[0]) =~ s/$_[1]/ my $output = ''; my @matches = map { substr($text, $-[$_], $+[$_] - $-[$_]) } 1 .. $#-; $template->process(\$_[2], { matches => \@matches }, \$output); $output /e; print $text; } foo("This is test 1\n", qr/test (.*)/, 'fish [% matches.1 %]');

    (Untested)

Re^3: How do I pass $1 to s///?
by Happy-the-monk (Canon) on Jan 06, 2006 at 17:24 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-16 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found