in reply to Re: undefined question
in thread undefined question

Thanks dws. Also informative. ONe thing though: I needed to make a small change.
while ( my $proc = <PROCS> ) { ... $found_one = 1; } if ( $found_one ) { print "looks okay here\n"; found_one = 0; } else { print "couldn't find $process\n"; }
W/o resetting the $found_one to 0, it would never alert me when the other processes (anything after 1) weren't running. As for the greps externally - I recall finding this in a perl tutorial many moons ago, and never learned it another way. Might you have a link that explains it internally?

Replies are listed 'Best First'.
Re: Re: Re: undefined question
by dws (Chancellor) on Jun 09, 2003 at 04:58 UTC
    As for the greps externally - I recall finding this in a perl tutorial many moons ago, and never learned it another way. Might you have a link that explains it internally?

    You'd find that described under "regular expressions". As an example,

    open(PROCS, "ps -a | grep $process |"); while ( my $proc = <PROCS> ) { # ... }
    can be rewriten (assuming $process holds an alphanumeric string) as
    open(PROCS, "ps -a |"); while ( my $proc = <PROCS> ) { next if $proc !~ /$process/; # ... }
    Regular expressions are your friends. Learning about them pays off in many ways.

      I've actaully been playing w/ regular expressions a bit lately. I wouldn't have thoght of using them w/ this though - this is pretty easy, after I got over my initial hurdle. They're still a bit foreign, but after reading (and asking) here, I've gotten them to do some pretty helpful things. Again - thanks for the wisdom