Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Are prototypes evil?

by BrowserUk (Pope)
on Sep 02, 2002 at 21:40 UTC ( #194640=note: print w/replies, xml ) Need Help??


in reply to Are prototypes evil?

I guess the best answer is the very last part of the "Prototypes" section of perlman:perlsub which concludes with:

And the split gets called in scalar context so it starts scribbling on your @_ parameter list. Ouch!

Effectively, using prototypes throws away one of the nicest and most unique features of perl, namely the context sensitivity of the calling eviroment. Using them renders wantarray superfluous.



Well It's better than the Abottoire, but Yorkshire!

Replies are listed 'Best First'.
Re: Re: Are prototypes evil?
by Django (Pilgrim) on Sep 02, 2002 at 21:53 UTC

    I think you're mixing up two things:
    A ($) prototype would force scalar input to a sub, but that doesn't have any influence on the return context.
    Look at this:

    sub Input ($) { wantarray ? split /,/ : $_; } my @List = Input $Source;

    ~Django
    "Why don't we ever challenge the spherical earth theory?"

      Your right! I was talking twaddle!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194640]
help
Chatterbox?
[james28909]: it would be to much work just to get around renaming three subs lol
[james28909]: but you could put it all in one sub and return the same data type that was inputted. i could write a small example maybe
[Lady_Aleena]: Their uses are also vastly different.
[Lady_Aleena]: The first two make hashes and arrays from a file, the third returns data from a pre-existing hash.
[Lady_Aleena]: Well, HoH and AoH respectively.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2017-05-24 05:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?