From: Robin <[EMAIL PROTECTED]>
> On Thursday 15 July 2004 07:08, Randal L. Schwartz wrote:
> > Yes.  Don't use prototypes.
> Why not? And is there another way to ensure things like lists are
> passed as references?

You can't pass a list by reference, you can only pass an ARRAY by 
reference!

See
        perldoc -q "What is the difference between a list and an array"

You can allways call the procedure like this:
        the_sub( [EMAIL PROTECTED], [EMAIL PROTECTED]);
and it's usualy clearer.

Also if you declare the function with the prototype you migh be 
restricting its ussage more than you think.

        sub foo (\@) {
                my $ary = shift;
                print "The array is ( '" . join("', '", @$ary) . "')\n";
        }
        @a = (1,2,3);
        foo(@a);
looks right yeah? And now call the subroutine with an anonymour 
array, without using any variable.
...
...
...
        foo( @{[1,2,3]} );
Nice isn't it?

I do not say do not ever use prototypes, but do be carefull and use 
them only if you "must".

Here are some links:
        Prototyping Subs: Good,Bad,Indifferent - on PerlMonks
        http://www.perlmonks.org/index.pl?node_id=288036

        FMTYEWTK about Prototypes by Tom Christiansen
        http://www.perl.com/pub/a/language/misc/fmproto.html
        (This seems to be broken at the moment, I've already sent an email
        to the perl.com admins.

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to