John W. Krahn wrote:
kapil.V wrote:
Hi,
Hello,
su-2.05b# df -h .
Filesystem Size Used Avail Capacity Mounted on
/dev/ad0s1e 136G 102G 23G 82% /home
From my script I do:
my $du = qx#df -h \.#;
($total,$used) = $du =~ /([0-9]+(\.[ 0-9]+)?)[ M|G]/sg;
^ ^ ^ ^
1 2 2 1
Your regular expression says to match one or more 0-9 characters
followed by a '.' character followed by one or more 0-9 or ' '
characters followed by a single character that is either ' ' or 'M' or
'|' or 'G'. The first pair of parentheses are capturing the first
number followed by the optional period and second number and the second
pair of parentheses are optionally (because of the ? modifier) capturing
a period followed by another number.
You are using the /s option which is superfluous because there is no '.'
character class in your pattern and you are using the /g option which is
superfluous because you are only capturing once.
Yeah, the /s is superfluous.
I used the /g modifier so that both the 'total' and 'used' are
captured. What I did not know was that $2 would be returned for a nested
paranthesis.
You have a numerical digit in the device name so it is possible that the
pattern will match that first instead of the size field (say for
instance /dev/ad0M.) You are using the -h switch with df so the size
for 'used' may appear to be higher than the size for 'total' (say for
instance that total is 100G and used is 900M.)
You probably need something like:
my ( undef, $du ) = qx!df -h .!;
my ( undef, $total, $used ) = map /(\d+)/, split ' ', $du;
print "Total:$total\nUsed:$used\ n";
Yeah, that is exactly what I want.
Output:
Total:136G
Used:
Why is "$used" not set?
John
Thanks.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/