Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
No, it's not my bug... it's a design failure in the language.

It is not said in the expert books on perl that you *must* put things in separate files. That's a made up requirement by people who didn't know or don't know how to call a bug a bug or work around it.

Fortunately, newer language constructs like 'use base' which says:

"base" employs some heuristics to determine if a module has already been loaded, if it has it doesn't try again. If "base" tries to "require" the module it will not die if it cannot find the modu +le's file, but will die on any other error. After all this, should y +our base class be empty, containing no symbols, it will die. This is use +ful for inheriting from classes in the same file as yourself, like so:
Now if you HVE to put things in separate files, why would could be going into the base that is specifically designed for when things aren't in separate files -- Why? Because perl wasn't designed to have the requirement that different classes be developed in separate files.

The fact that this does not work:

#!/usr/bin/perl -w use strict; package pkg; { our $var="foo"; our @EXPORT=qw($var); use Exporter qw(import); } package main; use strict; use warnings; import pkg; BEGIN { *var=\$pkg::var;} print "var=$var\n";
Is a bug in perl.

I try multiple ways, above to import that var. None of them work.

That doesn't mean you couldn't write various parts in BEGIN, but none of the introductory books written by the language authors say you should use BEGIN or separate files. To me -- that indicates that BEGIN's and separate files should tend toward being a more advanced topic -- while development of programs in 1 file should be considered the norm -- unless you want to break out functionality for use with other programs.

You shouldn't need to break apart a program if you are not trying to make libraries and if the program isn't getting "too long".

What is too long?

Taking perl as an example -- there are 147 "c" files in the 5.14.2 dist w/a total of 217508 lines. That's an average of 1500 lines/file. Most are small fails, but the meat of the main program is in large files.

In other projects 1500-3000 is not atypical for a single program -- with smaller files usually being library functions.

That people should think that breaking apart programs into little files is 'normal', goes against the norms of other languages.

I'm not certain, but I **think** (not sure) the only other language that might have such a similar requirement is 'java', the "Cobol" of the Web age.

I wouldn't call that a positive selling point.


In reply to Re^24: can't import using exporter by perl-diddler
in thread can't import using exporter by perl-diddler

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, 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, 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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (10)
    As of 2018-08-16 17:28 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Asked to put a square peg in a round hole, I would:









      Results (169 votes). Check out past polls.

      Notices?