Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to inspect variable

Tags:

variables

perl

I'm having a very difficult time inspecting the $return variable. The print "return = ". $return ."\n"; always comes back blank even though the process is still running. I do receive a warning about uninitialized variable. Can someone please explain?

my $process="MInstaller";
my $return=` ps -eaf |grep $process | grep -v grep`;
sub chk_proc{
  print "in chk_proc\n";
  print "\n";
  print "return = ". $return ."\n";
  while ( my $return ne "" ) {
   sleep(5);
  };
};
like image 324
user1718586 Avatar asked Feb 04 '26 09:02

user1718586


1 Answers

You're close. Your code doesn't works, because the variable $return in the

while ( my $return ne "" ) {

is another variable (declared in the scope of while) as your first $return.

You can try the next:

use 5.014;
use warnings;

chk_proc('[M]Installer'); #use the [] trick to avoid the 'grep -v grep :)

sub chk_proc{ while( qx(ps -eaf |grep $_[0]) ) {sleep 5} };
like image 101
jm666 Avatar answered Feb 07 '26 00:02

jm666