in reply to Re: Copy terminal lines-unix
in thread Copy terminal lines-unix

agree. but what about the cases when I need to pass and execute something like this:
./SaveCMD "ls | perl -lne 'print $_ if /-/'" --SaveCMD-- #!/usr/bin/perl use strict; open(OUT, ">>", "cmd-out") || die "$!"; print OUT "cmd: $ARGV[0] \n"; my $cmd = $ARGV[0]; print STDERR $cmd; my $out = qx($cmd); print OUT $out; close OUT;
in such situations I am not free to use $_ variable. any way to bypass this??

Replies are listed 'Best First'.
Re^3: Copy terminal lines-unix
by Corion (Patriarch) on Oct 06, 2015 at 09:45 UTC

    What makes you think that you are not free to use $_ in this situation?

    Maybe now it's a good time to learn about Perl, its syntax, especially about loops?

Re^3: Copy terminal lines-unix
by choroba (Cardinal) on Oct 06, 2015 at 12:13 UTC
    If you need to escape the dollar sign to prevent its expansion by the shell, use a backslash:
    ./SaveCMD "ls | perl -lne 'print \$_ if /-/'"
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ