开发者

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜