in reply to Effective way in perl
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Effective way in perl
by Rajsri (Initiate) on Jul 16, 2009 at 15:00 UTC | |
by graff (Chancellor) on Jul 16, 2009 at 17:27 UTC | |
by RajNaidu (Novice) on Jul 17, 2009 at 05:52 UTC | |
by RajNaidu (Novice) on Jul 17, 2009 at 08:50 UTC |