Rajini Naidu wrote:

On Tue, Jul 14, 2009 at 5:02 PM, John W. Krahn <jwkr...@shaw.ca> wrote:

Rajini Naidu wrote:

I have the below commands in the script.
`$swlist -l bundle -a revision -a architecture -s $t | $grep $n >>
$log_our_depot`;

`$swlist -l bundle -a revision -a architecture -s $t | $grep $n >>
$log_ourdepot_comp`;

Here I am outputting the same command line output to different logfile.
Is there a way in perl where I can output in one pass by storing it in a
variable.

open my $LOG1, '>>', $log_our_depot     or die "Cannot open
'$log_our_depot' $!";
open my $LOG2, '>>', $log_ourdepot_comp or die "Cannot open
'$log_ourdepot_comp' $!";

open my $PIPE, '-|', $swlist, '-l', 'bundle', '-a', 'revision', '-a',
'architecture', '-s', $t
   or die "Cannot open pipe from '$swlist' $!";

while ( <$PIPE> ) {
    next unless /$n/;
    print $LOG1 $_;
    print $LOG2 $_;
    }

close $PIPE or warn $! ? "Error closing '$swlist' pipe: $!"
                      : "Exit status $? from '$swlist'";

Hi John,

Thanks for the suggestions.

It now works fine.
I have one query, say suppose if I have below command to be executed in the
perl script, how do I include multiple greps.

$swlist -l bundle -a revision -a architecture -s $y | $grep $rel_string |
$grep $i | $grep AR

while ( <$PIPE> ) {

next unless /$n/;
The above loop works only for single grep, how do I modify for multiple
greps ?

while ( <$PIPE> ) {
    next unless /$rel_string/ && /$i/ && /AR/;
    print $LOG1 $_;
    print $LOG2 $_;
    }




John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to