Interesting idea.

I see two problems with it. The first is that while do 'file.pl'; looks neat and tidy, by the time you add the required error checking around each one it is less so and you'll find yourself wanting to wrap the error checking into a subroutine, which sort of defeats the purpose.

The second is that the code will be reinterpreted and compiled each time you need to use it, which would dramatically slow your script down.

You could avoid this by including the contents of the files using require 'file.pl'; but then you'd need to wrap the contents of the file in a subroutine so that you could call it more than once, or you have the same problems of reinterpreting it each time. Once you've wrapped it in a sub, your almost back to where you started, though it would achieve your aims of seperating "implementation from logic", but unless the routines in the files are going to be re-used in multiple programs, I would find it easier to maintain them all in a single file. And if they where to be re-used in multiple files, better to make it a module and use it.


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

In reply to Re: Do file.pl (replacing subs?) by BrowserUk
in thread Do file.pl (replacing subs?) by BUU

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.