Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Perl inline replace with execution results

by sk (Curate)
on Oct 23, 2005 at 05:39 UTC ( [id://502294]=note: print w/replies, xml ) Need Help??


in reply to Perl inline replace with execution results

Remove the \ before $1 and you need /e

If you run it without /e you will notice the string becomes `printhi`. Now you want to eval this expression and the /e takes care of that.

This works for me

#!/usr/bin/perl use strict; use warnings; my $str = "printmeprinthi"; $str =~ s/printme(.*)$/`$1`/e; print $str,$/;

my printhi program is

#!/bin/sh echo hi

output

hi

Log In?
Username:
Password:

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

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

    No recent polls found