perl regexp problem 2
I have a list of command to parse...
like:
> ls -lart
> ls
> ls /etc/passwd
> ping
> ping 127.0.0.1
> PING
> LS
I have to开发者_开发知识库 count the number of times ls and ping was executed, I have to not count uppercase variant like LS and PING, but I have to count command launch with option like "ls -lart"
How to check if a line contain the exact word ls or ping or whatever?
With regular expression!!!
Thanks,
my $count = 0;
while (<STDIN>) {
m/^\s*(ls|ping).*$/;
$count++ if $1;
}
精彩评论