Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
You have it backwards. It is not recommended because it is not preferred, and not vice versa.

The next question is why it is not preferred. Several reasons:

  1. If a script uses multiple modules that autoexport lots of stuff, it quickly gets hard to figure out where any given function came from. Give users the option to enforce sanity by documenting what came from where.
  2. When independent modules put things into package main, it becomes very easy for private functions in one to conflict with private functions in another. Tracking down and resolving these conflicts grows more complex rapidly as the number of functions and files grows. (With 5 files you only have 1/4 the number of possible lines of conflict as you do with 10.) Putting each file in its own package reduces the damage from such internal conflicts.
  3. It is preferred that you not export every function. Good modularity in procedural code is to have each module have a simple API. A ton of exported functions is a very complex API.
There are more reasons, plenty of them, but those will do for now. If you want the rest, along with plenty of other good advice, I can highly recommend Code Complete. (No, that is not a Perl book. But good programming technique is not Perl-specific.)

Yes, you can do what you ask for. Perl gives you enough rope to hang yourself. But that doesn't mean that you should do it...

UPDATE: I used the word "recommended" where I really meant "preferred".


In reply to Re: Re: Re: Re: Re: Confused about splitting program into multiple files. by tilly
in thread Confused about splitting program into multiple files. by disciple

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2021-11-30 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?