novice2015 has asked for the wisdom of the Perl Monks concerning the following question:

I have a command like this and I want to break it into 2 lines. Does anyone know how to do this? I use \ in bash - don't know what it is in perl.
my @bpx = qx(/local/mnt/quadmcd/bcommand -pol "${line}" -sl TIMESTATE + -d $final_start -e $final_end -L |grep -i "inventoryid:" |awk '{prin +t $3}');

Replies are listed 'Best First'.
Re: qx command -breaking the line
by salva (Canon) on Jun 18, 2016 at 10:20 UTC
    my @bpx = readpipe('/local/mnt/quadmcd/bcommand -pol "${line}" -sl TIM +ESTATE -d $final_start -e $final_end -L |' . 'grep -i "inventoryid:" |' . 'awk "{print $3}"');

    Update: s/(pipe)(read)/$2$1/;

Re: qx command -breaking the line
by Anonymous Monk on Jun 17, 2016 at 22:17 UTC
    A string is a string, see perlintro, perlquote
    my $command = qq{/local/mnt/quadcmd/bcommand -pol "$(line) "}; $command .= q{ -s1 TIMESTATE }; $command .= qq{ -d "$final_start" }; $command .= qq{ -e "$final_end" }; $command .= qq{ -L }; $command .= qq{|grep -i "inventoryid:" }; $command .= q{|awk '{print $3}' }; my @bpx = qx{$command};
Re: qx command -breaking the line
by Anonymous Monk on Jun 17, 2016 at 22:14 UTC

    One way - use Perl instead of shelling out to grep and awk: (untested)

    use IPC::System::Simple 'capturex'; my @bpx; for (capturex('/local/mnt/quadmcd/bcommand', '-pol', $line, '-sl', 'TIMESTATE', '-d', $final_start, '-e', $final_end, '-L')) { next unless /inventoryid:/i; my @F = split; push @bpx, $F[2]; }
Re: qx command -breaking the line
by Anonymous Monk on Jun 17, 2016 at 22:28 UTC

    Does the command even work in the first place?

    qx(... | awk '{print $3}')

    That would be Perl's $3, not awk's $3.