Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Searching strings within an array for a particular word.

by beppu (Hermit)
on Mar 06, 2002 at 01:41 UTC ( [id://149585]=note: print w/replies, xml ) Need Help??


in reply to Searching strings within an array for a particular word.

How's this?
#!/usr/bin/perl -w use strict; sub is_running { my $process = shift; # name of process my @p = grep { !/grep/ } `ps aux | grep $process`; # ps aux without the greps print @p; # comment this out return scalar @p; # false if @p is empty; true otherwise } # test program foreach (qw(httpd sshd syslogd telnetd ftpd yourmama)) { printf("$_ %s running.\n", (is_running($_) ? "is" : "is not")); }

w/ the experimental syntax-highlighted remix

#!/usr/bin/perl -w

use strict;

sub is_running {
    my $process = shift;    # name of process
    my @p = grep { !/grep/ } `ps aux | grep $process`;
                            # ps aux without the greps
    print @p;               # comment this out
    return scalar @p;       # false if @p is empty; true otherwise
}

# test program
foreach (qw(httpd sshd syslogd telnetd ftpd yourmama)) {
    printf("$_ %s running.\n", (is_running($_) ? "is" : "is not"));
}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://149585]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 01:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found