Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^5: How do I prototype a function with a varying number of arguments?

by koolgirl (Hermit)
on Jul 30, 2011 at 02:14 UTC ( [id://917583]=note: print w/replies, xml ) Need Help??


in reply to Re^4: How do I prototype a function with a varying number of arguments?
in thread How do I prototype a function with a varying number of arguments?

Hhmm, so, I'm sitting here looking at your question and my obvious answer, and I think maybe I'm seeing the point you maybe were trying to get me to see.....the $$ prototype isn't really a limitation, it's just a declaration of how many scalar arguments a function takes, like a <cmp> function, for example...or perhaps it's late and I'm thinking a bit too hard on this one.....

UPDATE:

OK, so I was thinking too hard...apparently it seems my original notions about prototypes making functions less generic is shared by quite a few of you out there. Well, this goes fantastic with one of my other recent posts, lol, especially related to planetscape's "brain fart" reply, which this last reply of mine most definitely seems to qualify as..*turns red* ;P

Replies are listed 'Best First'.
Re^6: How do I prototype a function with a varying number of arguments?
by eyepopslikeamosquito (Archbishop) on Jul 30, 2011 at 07:22 UTC

    I think maybe I'm seeing the point you maybe were trying to get me to see.....the $$ prototype isn't really a limitation
    Perhaps the point is that the $$ prototype can be a (confusing) limitation. For example:
    use strict; use warnings; sub Fred($$) { my $arg1 = shift; my $arg2 = shift; print "arg1='$arg1'\n"; print "arg2='$arg2'\n"; } my @two_elt_arr = ( 'abc', 'def' ); Fred(@two_elt_arr); # oops, compile error: "Not e +nough arguments" Fred($two_elt_arr[0], $two_elt_arr[1]); # this works
    See Modern Perl, "The Problem with Prototypes", page 242:
    Prototype coercions work in subtle ways, such as enforcing scalar context on incoming arguments ... (examples elided) ... Those aren't even the subtler kinds of confusion you can get from prototypes.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://917583]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-03-29 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found