Next | Program Repair Shop | 135 |
Someone answering the question of the previous slide suggested:
my ( $user, $system, $nice, $idle ) =
`top -b -n 0` =~
/^CPU states:\s+([0-9.]+)% user,\s+([0-9.]+)% system,\s+([0-9.]+)% nice,\s+([0
-9.]+)% idle/m;
This is how Perl gets a reputation for being unreadable
Capturing the Same Pattern Repeatedly
Here we capture ([0-9.]+) four times
Often, this can be replaced with m//g or with split
As on the previous slide:
($user, $system, $nice, $idle) = ($line =~ m/[0-9.]+/g);
Next | Copyright © 2002 M. J. Dominus |