Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Perl inline replace with execution results

by sk (Curate)
on Oct 23, 2005 at 05:39 UTC ( #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


Comment on Re: Perl inline replace with execution results
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2015-07-31 00:47 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 (274 votes), past polls