On 30/10/2011 13:20, newbie01 perl wrote:
Hi Rob,

Thanks for your response and to everyone else who had given their thoughts,
especially John. This whole exercise is turning out to be a "fun" way of
learning arrays and print formatting.

I tried the script that you suggested and it is giving some error and not
sure how to get around it. FYI, I commented out use strict and use warnings
for the time being 'coz it gives error as below:

Use of implicit split to @_ is deprecated at ./df.pl line 30.
Bareword "MBytes" not allowed while "strict subs" in use at ./df.pl line 32.
Bareword "GBytes" not allowed while "strict subs" in use at ./df.pl line 33.
Execution of ./df.pl aborted due to compilation errors.

I then run the script and it gives error as below:

Can't locate object method "rec" via package "Filesystem" (perhaps you
forgot to load "Filesystem"?) at ./df.pl line 30.

Does it matter that the df -k header is not Filesystem KBytes Used Avail
Capacity Mount?

For Solaris, the header is
Filesystem            kbytes    used   avail capacity  Mounted on

For Linux, the header is
Filesystem           1K-blocks      Used Available Use% Mounted on

Note that the Filesystem KBytes Used Avail Capacity Mount is a
pre-formatted header in the UNIX shell version of the script. Also, the df
-k output for example on a Linux system will sometimes flow over one (1)
line, example below. FYI, if re-directed to a file, all output line are
one-liner, if re-directed to STDOUT, output is as shown below. Perhaps the my
@data = `df -k`; line is giving the same output when df is not re-directed
to a file. Will check that out.

You must never run your program without strict or warnings. Removing
them doesn't fix any bugs, it just stops Perl telling you about them!

In this case you have copied my program wrongly - the lines in the
foreach (@data) loop are missing @ and $ signs. The correct version
(copied from my original post) is below.

Rob


foreach (@data) {

  my %rec;
  @rec{qw/Filesystem KBytes Used Avail Capacity Mount/} = split;

  $rec{MBytes} = kb_to_mb $rec{KBytes};
  $rec{GBytes} = kb_to_gb $rec{KBytes};

  $rec{$_} = kb_to_mb $rec{$_} for qw/Used Avail/;

  $_ = \%rec;
}

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


Reply via email to