Re: extracting values from vmstat output

Tim Greer <tim@xxxxxxxxxxxxx> writes:

alfonsobaldaserra wrote:

# untested
my $vmstat = qx/vmstat -v/;
my($memory) = $vmstat =~ /(\d+) memory pages/;
my($free)   = $vmstat =~ /(\d+) free pages/;

your untested code turned out to be perfect. i got what i wanted.
thank you.

but i have one question could you please answer? why are you using
$memory and $free in list context? i tried running it as scalar and
the output was 1 but in list context it gives correct value.

One method is the result of the "test" of that condition (matching),
while the other assigns the value returned (not true or false). It's
not that it's in a list context

Context is *exactly* what makes that difference. In scalar context,
the =~ operator returns true/false, and in list context it returns a list
of the matched subexpressions.

See 'perldoc perlop' and 'perldoc perlre' for details.


My blog:
Cocoa programming in Perl: