On 10/21/2011 07:18 PM, newbie01 perl wrote:
Am trying to write/convert a customized df script...
> I've attached a version of the script in Korn shell. ...
...
[input]
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/md/dsk/d1       3099287 2482045  555257    82%    /
/proc                      0       0       0     0%    /proc
mnttab                     0       0       0     0%    /etc/mnttab
...
> Sample output of the run using the Korn shell script as below:
> Filesystem MBytes Used Avail
> Capacity Mount
> --------------------------------------------- --------- --------- ---------
> -------- -----------------------------------
> /dev/md/dsk/d1                                   3027-MB   2424-MB
> 542-MB      82% /
> /dev/md/dsk/d3                                   3027-MB   1560-MB
> 1406-MB      53% /var
> /dev/md/dsk/d4                                   4886-MB   4229-MB
> 608-MB      88% /opt

Perl is eminently suited to that task, and more.  :-)


 I can't find a Perl max or min function :(-

Please see the List::Util module:

    http://search.cpan.org/~gbarr/Scalar-List-Utils-1.23/lib/List/Util.pm


> Would be nice if I can use the df header as hash references

Split, arrays, hashes, hash slices, data structures, comma-separated values (CSV), and structured query language (SQL) all come to mind. One of Perl's slogans is:

    "There's more than one way to do it."

    http://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it

Inferring the exact number of ways is an exercise left to the reader.  ;-)


Clearly, you are comfortable with the Unix command line environment. Perl would be a good addition to your skill set.


* 授人以魚不如授人以漁(授人以鱼不如授人以渔)。(pinyin: Shòu rén yǐ yú bùrú shòu rén yǐ yú) o Literally: Teach a man to take a fish is not equal to teach a man how to fish. o Meaning: Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.

    http://en.wikiquote.org/wiki/Chinese_proverbs


There are many ways to learn Perl. I prefer printed books, supplemented with online documentation (perldoc, FAQ, tutorials), various WWW sites, and mailing lists. And, of course, lots of practice.


The canonical book for learning Perl is "Learning Perl":

    http://shop.oreilly.com/product/0636920018452.do


"Perl Cookbook" is a well-organized guide book full of practical code snippets for solving common programming chores ("what" and "how"). The explanations are excellent ("why"). This book will take you from writing toy scripts to writing really useful scripts:

    http://shop.oreilly.com/product/9780596003135.do


"Programming Perl" is the canonical Perl reference book. A new version is due out in December:

    http://shop.oreilly.com/product/9780596004927.do


I recommend that you get the first two right away.


HTH,

David


--
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