Anirban Adhikary wrote:
Dear list

Hello,

while I am running the following code I am getting a warning message. the
code is as follows

  1 use strict;
  2 use warnings;
  3 use Cwd 'abs_path';
  4 my $dir = "/home/oraoneload_beta/sraywork/beta2.2/OraOneLoadServer";
  5 chdir($dir);
  6 #my $filename="$dir/processinfo.txt";
  7 #`ps -U oraoneload_beta  -u oraoneload_beta u | grep perl | grep -v grep
$filename`;
  8 open(FH,"ps -U oraoneload_beta  -u oraoneload_beta u | grep perl | grep
-v grep|") or "can't open : $!";
  9 #open(FH,"$filename");
 10 my @process = <FH>;
 11 close(FH);
 12 chomp(@process);
 13 pop(@process);
 14 foreach my $el(@process)
 15  {
 16    my $cmd =(split /\s+/,$el)[12];
 17    my ($a,$b) = split(/\//,$cmd);
 18     my $path=abs_path($b);
 20     print $path."\n";
 21 }
 22

The warning message is as Useless use of string in void context at
processcheck.pl line 8. But while I am commenting the line 8 and
uncommenting the the line 6, 7 and 9 and then running this script I am not
getting any warning message. Where I am making the mistake?

Your mistake is on line 8 at:

or "can't open : $!"

You have to put something like 'die' between 'or' and '"'.


Also, you may do better with code like this instead:

use strict;
use warnings;
use Cwd 'abs_path';

my $dir = '/home/oraoneload_beta/sraywork/beta2.2/OraOneLoadServer';
chdir $dir or die "Cannot chdir to '$dir' $!";

open my $FH, '-|', qw/ps -U oraoneload_beta -u oraoneload_beta -o command/ or die "Cannot open pipe from 'ps' $!";

while ( <$FH> ) {
    next unless /perl/;
    chomp;
    my $cmd =( split ' ', $_, 3 )[ 2 ];
    my $path = abs_path( ( split /\//, $cmd )[ 1 ] );
    print "$path\n";
    }

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

__END__



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to