Re: Appending a character to a field



Try to use this way,

use strict;
my $percent=90;
my @df;

open(DFOUT, "df -k|");
while (<DFOUT>) {
next if /Filesystem/i;
my ($free) = /(\d+)%/;
if ( $free >= $percent ) {
push(@df, $_);
}
}
close DFOUT;

print "@df";



2007/8/30, bokjasong@xxxxxxxxx <bokjasong@xxxxxxxxx>:


Hi,


I'm a perl newbie and would like to ask this question here.

Let's say I have the following code. Trying to check the disk space,
it's to truncate the percent sign % from the df -k output, compare the
percentage field to see if it's bigger than 90%, and grasp only those
lines that are and push those to an array @df. But how can I add the
percentage sign back to the percentage field on each line for the
proper output? I put down ??????? as below to find out what regexp
needs to be there in the below.


$percent=90;

open(DFOUT, "/usr/bin/df -k|");
while (<DFOUT>) {
next if ($_ =~ /Filesystem/i);
s/\%//; # to remove the percent sign for
comparison
if ( (split)[4] >= $percent ) {
???????
push(@df, $_);
}
}


print "@dfoutput\n";

I appreciate your help very much!

Thank you.


- Bok


--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/



.



Relevant Pages

  • Re: Net::LDAP compare question
    ... I added "use strict;" and found some defects. ... I think I am doing something wrong as far as the compare statement. ... go to the next entry. ...
    (comp.lang.perl.modules)
  • Appending a character to a field
    ... I'm a perl newbie and would like to ask this question here. ... Trying to check the disk space, ... it's to truncate the percent sign % from the df -k output, compare the ...
    (perl.beginners)
  • Re: List to hash/dict?
    ... and passes their second components to compare. ... In the second version the comparator passes to compare two expressions ... are usually strict by their nature. ... But if this call site is polymorphic, the compiler can't a priori ...
    (comp.lang.functional)
  • Re: Checking on logical functionality
    ... The content of file1 is A&B while file 2 ... How can I compare and print that the functionality is same. ... use strict; use warnings; ... sub A ...
    (perl.beginners)
  • Re: SAT question
    ... jennifer wrote: ... Indeed that makes C less than A+B, but if you compare ... In a nondegenerate triangle, the strict ... inequality has to hold for all three sides. ...
    (sci.math)