PROTO in sub NAME (PROTO) {

2004-09-21 Thread Jeremy Kister
how is the (PROTO) operator in 'sub NAME (PROTO) {' supposed to be useful ?

sub foo {
sub foo ($) {
sub foo ($$) {
sub foo ($$$) {
sub foo ($@) {
sub foo (@) {


i see the relation to the amount of arguments supposed to be in @_ ---

my handy perl QRG provides a worthless explenation.

there doesnt seem to be any warning or error when you ($$$) but only provide
1 argument, for example.



Jeremy Kister
http://jeremy.kister.net/


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




Re: PROTO in sub NAME (PROTO) {

2004-09-21 Thread WilliamGunther
Prototyping can be useful in Perl. It shouldn't be overused, however. They  
can be powerful when trying to make functions that look and feel like 
built-ins.  Trying to, for example, create a subroutine that looks like map, grep, and 
sort  is made by prototyping it as (@) (will pass coderef and an array). If 
you  want to accept an array and handle it like splice does you can do (\@;@)  
(will pass array ref and an optional array). 
 
There are very specific examples found in the manual in perldoc  perlsub.
 
And there is a warning IF the subroutine is declared before you call  it.
 
Prototyping(1,2);  #No exception, just a warning
 
sub Prototyping ($$$) {
print pop;
}
 
Prototyping 1, 2, 3; #Good job
Prototyping(1,2); #works, read perldoc perlsub
Prototyping(1); #Death
 
I'm an advocate of prototyping. I like the power it can display in making  
your own functions behave like built-ins. But you can't go crazy with it and  
prototype every sub you write. Only do it when it makes your and the  
enduser's/maintainer's life easier.

--
-will  
http://www.wgunther.tk
(the above message is double rot13 encoded for  security reasons)

Most Useful Perl  Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite 
 

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




Re: PROTO in sub NAME (PROTO) {

2004-09-21 Thread Jeff 'japhy' Pinyan
On Sep 21, Jeremy Kister said:

how is the (PROTO) operator in 'sub NAME (PROTO) {' supposed to be useful ?

Prototypes are only useful:

1. when the function is prototyped BEFORE it is called,
2. when the function is called without an , and
3. when the function is not a method of an object.

See the documentation for prototypes.  Chances are, you don't need them.

-- 
Jeff japhy Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart


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