Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hello my friend perlancar,

you already had the perfect, concise answer by choroba, but let me expand something that can be useful.

 use Module;   <=>  BEGIN { require Module; Module->import( LIST ); }

ikegami on SO explains it in this way:

# script.pl use Foo; my $foo = Foo->new(); $foo->do(); # does: 1.Compile script.pl 1.Compile use Foo; 2.Execute require Foo; 1.Compile Foo.pm 1. ... 2.Execute Foo.pm 1. ... 3.Execute import Foo; 4.Compile my $foo = Foo->new(); 5.Compile $foo->do(); 2.Execute script.pl 1.Execute my $foo = Foo->new(); 2.Execute $foo->do();

Wich unveils the compiletime/runtime dicotomy.

Also very interesting read is Re: RunTime & compile Time Doubt on Perl (many) and the document I always called twelve pillars of wisdom (but i do not remember if it was named this way..) as found in perlmod

print "10. Ordinary code runs at runtime.\n"; END { print "16. So this is the end of the tale.\n" } INIT { print " 7. INIT blocks run FIFO just before runtime.\n" } UNITCHECK { print " 4. And therefore before any CHECK blocks +.\n" } CHECK { print " 6. So this is the sixth line.\n" } print "11. It runs in order, of course.\n"; BEGIN { print " 1. BEGIN blocks run FIFO during compilation.\n" } END { print "15. Read perlmod for the rest of the story.\n" } CHECK { print " 5. CHECK blocks run LIFO after all compilation.\n" } INIT { print " 8. Run this again, using Perl's -c switch.\n" } print "12. This is anti-obfuscated code.\n"; END { print "14. END blocks run LIFO at quitting time.\n" } BEGIN { print " 2. So this line comes out second.\n" } UNITCHECK { print " 3. UNITCHECK blocks run LIFO after each file is +compiled.\n" } INIT { print " 9. You'll see the difference right away.\n" } print "13. It only _looks_ like it should be confusing.\n" +;

other interesting reads are at your disposal in my bibliotheca

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: Assignment and use statement in the same BEGIN block by Discipulus
in thread Assignment and use statement in the same BEGIN block by perlancar

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 rifling through the Monastery: (5)
    As of 2019-09-22 10:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The room is dark, and your next move is ...












      Results (273 votes). Check out past polls.

      Notices?