in reply to Backtics execution with multiple lines

Since backticks interpolate variables, one straight-forward solution would be to store your desired system command in a string and then execute it. Perhaps something like this:

my $string = 'This will all be '; $string .= 'one string.'; `$string`;

You could also use the system command, which would let you split your command and arguments into terms in an array, which is then passed to the OS. You should also take a look at exec. Missed the return string requirement - sorry.

Replies are listed 'Best First'.
Re^2: Backtics execution with multiple lines
by ikegami (Patriarch) on Feb 04, 2009 at 17:58 UTC

    Backticks capture output, but system doesn't. Using exec directly is too much work. open '|-' would be the appropriate choice here.

    $ perl -e' > my @cmd = ( echo => "foo\nbar" ); > open(my $fh, "|-", @cmd); > print <$fh>; > ' foo bar

    Bonus: The shell isn't involved if the command has an argument.