--- John <[EMAIL PROTECTED]> wrote:
> Does anyone have a cheetsheat for function prototyping - how to say 
> that a parameter is a scalar, array, hash, reference, etc., and whether 
> it is required or optional?

John,

Here's the cheatsheet for function prototypes:

    Don't use 'em.

There are a few special cases where function prototypes are good, but those are few 
and far
between.

They are useful when specifying a null prototype, as is done with "use constant".  
They can also
be used to simulate tricky constructs like a try/catch block:

    sub try (&$) {
        my ($try, $catch) = @_;
        eval { &$try };
        if ($@) {
            local $_ = $@;
            &$catch;
        }
    }

    sub catch (&) { $_[0] }

    try {
        die "phooey";
    }
    catch {
        /phooey/ and print "unphooey\n";
    };

Was that confusing?  Good.  It should be.  Generally, the "trickier" the code, the 
more buggy it's
likely to be (unless you are Dr. Damian Conway).  Perl prototypes are rarely, if ever, 
a good
solution to a problem.  Further, they're not even prototypes in the sense that most 
other
languages use the term.  Thus, if trying to bring another languages expertise to Perl 
and using
prototypes, you're going to get bit by bugs.  Also, because method calls are 
determined at
runtime, but prototypes are checked at compile time, thus ensuring that prototypes 
don't work with
OO programming.

Read this for more information:  http://www.perl.com/pub/a/language/misc/fmproto.html

It will explain the problems, but it will also answer your questions.

Cheers,
Curtis "Ovid" Poe

=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A

__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to