Another place where AUTOLOAD can be useful, apart from TedYoung's suggestion, is when you are implementing a remote invocation handler.

The problem: you want your code to use regular funciton calls, but run on a remote machine.

The solution: write an AUTOLOAD routine that catches each request of this type, checks it against a list of valid commands to run, sends the request and the parameters over the wire somehow to the other end, and communicates the results. (There can be many variations of this idea; a common one being to put the validation on the server side of things. This is actually better design, because a server should generally not trust just anything a client gives it.)

On the other side, you have to actually run some function by its name. This, if you've been reading <cite>Advanced Perl Programming</cite>, is closely related to symbol table stuff, although you don't necessarily pass a typeglob around explicitly. And although you didn't ask about it, it is also an example of a good time for turninig off use strict :)

As for END blocks, they're convenient places to place cleanup code. Delete temporaray files, close database connections... of course, if your code is simple and has one possible flow, you may not need this.


In reply to Re: which use for any Perl elements? by gaal
in thread which use for any Perl elements? by mat21

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.