Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Style & subroutine organization

by HamNRye (Monk)
on Aug 30, 2001 at 00:07 UTC ( [id://108872]=note: print w/replies, xml ) Need Help??


in reply to Style & subroutine organization

I do not maintain that this is the best way to do it, it's just my way....

I like to think of my subroutines in terms of giving instructions.

@lines = &readFile ; @output = &parseLines(@lines) ; &doReport(@output) ;

The reason I use this method is for readability. Read the file to get the lines, parse the lines to get the output, use the output to do the report. It allows me to quickly find the errant code block if there is a problem, and in the design phase I am left with a good outline to build my program around.

Now, on to questions of efficiency, mem footprint, etc... I don't really care. According to my boss, all of the servers work fast enough and I don't. Hence, my main goal is to speed up my work. Also, in a modern computer you should have better than 64MB of RAM, and the space taken up by some of the extra arrays is totally negligible.

Also, look at this write up by Merlyn on references. Passing references to subs will simplify your life at some point.

To redo your example my way:

$f1 = func1(); $f2 = func2($f1); $f3 = func3($f2); print $f3; (or) print func3($f2);
Hope it helps... ~Hammy

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://108872]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2024-04-23 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found