On Tue, 2006-06-06 at 18:59 +0800, joseph wrote:
> All,
> 
> Just like to ask for correction on what's wrong with my script it gives spit 
> out this error when i run it.
> 
> Unsuccessful open on filename containing newline at disksize.pl line 8.
> Can't open file No such file or directory
> 
> But it runs without this error whenever i feed it up when an existing file 
> output by df-h.
> ex:## open(FL,"path/toactual/file") or die "blabalha";
> Does this mean it can't trap the output of  `df-h`?
> 
> Here's the script###
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> chomp(my $output_file = `df -h`);

$output_file =~ s/\r//g;
# chomp only removes linefeed characters \n

# BTW, there is no such thing as a newline;
# it is either a linefeed: \n ASCII LF 0x0A
# or a carriage return: \r ASCII CR 0x0D

> 
> open(FL,"$output_file") or die "Can't open file $!\n";

... or die "cannot open file '$output_file': $!\n";
# print out the contents so you can see exactly what it contains.

> my @list;
> my %disk;
> my($label,$size,$use,$avail,$percent,$mounted,$partition,$usage);
> while(<FL>) {
>      ($label,$size,$use,$avail,$percent,$mounted) = split(/\s+/, $_);
>      push @list,$mounted,$percent;
> }
> 
> %disk =(@list);
> delete $disk{"Mounted"};
> 
> 
> 
> foreach (sort keys %disk) {
>        my $value = $disk{$_};
>        print "\t $_ => $value \n";
> }



-- 
__END__

Just my 0.00000002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to