利用正则匹配内容直接赋值

ken@ken-PC:~$ who

ken     tty7       2012-02-09 08:49 (:0)
ken     pts/0     2012-02-09 16:51 (:0.0)

 

 my (%ttys,$user,$tty,$data);

for (`who`){

    ($user,$tty,$data)= /(\S+)\s+(\S+)\s+(.*)/;

  $ttys{$user} .= "$tty at $data\n";

}

posted @ 2012-02-09 17:08  沉默爆破手  阅读(320)  评论(0编辑  收藏  举报