Re: extracting values from vmstat output
- From: Sherm Pendley <spamtrap@xxxxxxxxxxx>
- Date: Thu, 19 Feb 2009 02:26:54 -0500
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.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
.
- Follow-Ups:
- Re: extracting values from vmstat output
- From: Tim Greer
- Re: extracting values from vmstat output
- References:
- extracting values from vmstat output
- From: alfonsobaldaserra
- Re: extracting values from vmstat output
- From: Tad J McClellan
- Re: extracting values from vmstat output
- From: alfonsobaldaserra
- Re: extracting values from vmstat output
- From: Tim Greer
- extracting values from vmstat output
- Prev by Date: Re: extracting values from vmstat output
- Next by Date: FAQ 6.21 Are Perl regexes DFAs or NFAs? Are they POSIX compliant?
- Previous by thread: Re: extracting values from vmstat output
- Next by thread: Re: extracting values from vmstat output
- Index(es):
Relevant Pages
|