Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: uptime Message-ID: <1991May31.122828.8190@convex.com> Date: 31 May 91 12:28:28 GMT References: Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 29 Nntp-Posting-Host: pixel.convex.com From the keyboard of subbarao@phoenix.Princeton.EDU (Kartik Subbarao): :I was wondering whether there's any nicer ways to do this: : :$usavgs = `/usr/ucb/uptime`; : :if ($usavgs =~ /.*,(.*)user.*average: *(.*),(.*),(.*)/) { : $users = $1; : $avg1 = $2; $avg2 = $3; $avg3 = $4; :} : :print $users, "\t", $avg1, "\t", $avg2, "\t", $avg3, "\n"; : : :I want to get the number of users, and the load averages into different :variables so I can print them out nicely for another program to scanf. : :I was originally thinking of doing some split()s and/or substr()s, but that :would seem to take longer. How does this method compare to others? Go wish the regexp: remember, one of the things that perl is *about* is pattern matching. Don't be afraid of using it. Avoid splits. print join("\t", `uptime` =~ /.*,(.*)user.*average: *(.*),(.*),(.*)/), "\n"; --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "So much mail, so little time."