There's more than one way to do things | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
hello raywood and welcome to the monastery and to the wonderful world of Perl!
well learning by doing is a great thing but before you must learn by reading. Read solid and idiomatic example similar to your need is the first step to end with a fluent Perl. I always suggest the read of Perl Cookbook; it is a book a little bit aged but contains perfectly valid perl solution to common problems with clear explainations. If you want to mitigate the age of the book take you free copy of Modern Perl book: as suggested is a great book that discert about Perl following it's principles and concepts. You took an example by a poweful monk: i'm sure it is from BrowserUk because of the almost-signature perl -slw and it is wise to choose good exmamples but it is even wiser to understand deeply what the code really do (for instance -s perl switch can be useful while testing a script but can introduce very strange behaviors.. are you aware of them? no? do not use it!). I say this because it is better have your own simple code and submit it here for revision, code that you understand fully, that code by someone else if you only understand it for an half. Now answers: 1) RAM is always involved and generally it is no good to waste it: that said I guess ancient WordStar (Oh WordStar I remember it: was the first word processor I used it on the 286 of my father) file will never eat your 16Gb RAM. Anyway when your slurp entirely a file it goes entirely in the RAM used by your perl process (with the little overhead of the variable that contains it). So it genarally wiser to process a file line by line than slurping it. Try it yourself observing the following two programs in the process manager this slurp the file
while this iterates over it
Try these programs passing to them a 1Mb, 100Mb, 1Gb text file files and observe what happens 2) to adapt your program to process different files the simplest solution is to pass them as arguments in the command line: they will fill the @ARGV array. See perlvar for it. So you can have something like:
3) Every Perl release is backward compatible so pick the more modern with a even minor version ie: 5.24 HtH L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS. In reply to Re: Learning Perl by Doing.. Learn by reading too
by Discipulus
|
|