in reply to Perl inline replace with execution results

sk found two problems, here's a couple more. Your mytool.pl line will not run without a path indication unless its directory is in your $PATH. Double quoting is undesirable since it will make the shell try to interpolate. This works for me,

$ cat >mytool.pl #!/usr/bin/perl print 'Substitute string'; $ chmod 755 mytool.pl $ cat >test.tmpl This is mytool.pl foo $ perl -pe's/(mytool\.pl\b.*)/`.\/$1`/e' test.tmpl This is Substitute string $
It was necessary to escape '/' in the path because we used it for the substitution delimiter.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Perl inline replace with execution results
by skerr1 (Sexton) on Oct 23, 2005 at 13:26 UTC
    (Updated to thank the proper folks. :) Thanks for all the friendly reminders)

    Excellent zaxo and sk! You make it look too easy. :)

    zaxo, you are right about the double quotes and that is why I had the "\" before the "$1". In my original try I had single quotes, but there I saw that it wasn't executing, but rather just replacing with exactly what I wanted to execute. So, I want to run this from the cmd line and I'll mix up what the two of you both shared.

    I finally went with this (mytool.pl is in my PATH):

    perl -i.bak -pe 's/^(mytool\.pl .*)/`$1`/e' test.template

    Nice. Thank you both!

    Shannon Kerr