in reply to extract problem
For the total line, isn't $1="Total", $2="0", $3="0", $4="0", $5="", $6=""? Try:
my $part = `sysutil | grep Total`;
or just
my ($part) = grep { /^\s*Total/ } `sysutil`;
Of course, you probably want to extract the three numbers:
my ($conn, $sess, $job) = (split(/\s+/, (grep { /^\s*Total/ } `sysutil +`)[0]))[2..4];
Update: Ug, that was ugly, let's try:
my ($part) = grep { /^\s*Total/ } `sysutil`; my ($conn, $sess, $job) = (split(/\s+/, $part))[2..4];
or
my ($conn, $sess, $job) = `sysutil` =~ /^ \s+ Total \s+ (\S+) \s+ (\S+) \s+ (\S+) /xm;
or functional style
sub select_fields { @_[@{shift(@_)}] } sub head { $_[0] } # Shortcut for "select_fields [0]," my ($conn, $sess, $job) = select_fields [2..4], # Extract totals. split /\s+/, # Split into fields. head # List to scalar. grep { /^\s*Total/ } # Extract total line. `sysutil`; # Get data.
Update: Forgot that `` in list context splits on $/. Simplified the above. jpeg++.
|
|---|