You seem to be running the same command two times, just to have its output stored in two distinct output files. Apart from that, I'd be worried about the risks of running shell commands that way, unless there is very hight certainty that the perl variables being used to build the command are "safe" (contain no shell metacharacters, etc).

In any case, it seems like you only need a shell to run the initial part of your pipeline, and it would be just as well for perl to do the rest:

my @command = ( $swlist, '-l', 'depot', '@', $depot_locn ); my $child_pid = open( my $shell, '-|', @command ) or die "shell command failed: $!\n"; open( my $out1, ">>", $log_std_depot ) or die "$log_std_depot: $!\n"; open( my $out2, ">>", $temp_log ) or die "$temp_log: $!\n"; print $out1 "COMMAND: @command ## FILTERS: $rel_string / $i / AR\n"; while (<$shell>) { next unless ( /$rel_string/ and /$i/ and /AR/ ); print $out1 $_; print $out2 $_; } close $out1; close $out2; close $shell;

Update: note that by doing the "grep" parts inside perl, you are able to make use of perl's much more powerful regex syntax -- you can do things that would not be possible with the standard command-line grep tool.

Another update: changed the code snippet to open the two output file in append mode (>> as per the OP code) rather than "truncate" mode.


In reply to Re: Effective way in perl by graff
in thread Effective way in perl by RajNaidu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.