Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: The purpose of prototypes in perl subroutines

by jjhorner (Hermit)
on Apr 13, 2005 at 15:13 UTC ( [id://447449]=note: print w/replies, xml ) Need Help??


in reply to The purpose of prototypes in perl subroutines

Prototyping has a use when running with the strict 'subs' pragma. While it is in effect, you will have to prototype your subs to use the bareword style when calling:
sub mysub; print mysub;
or, use the ampersand or parens:
print mysub();
*** Special thanks to Nat Torkington. I've been reading Jon Orwant's Computer Science and Perl Programming book lately. Good information, and a good review of perl topics you may have forgotten. Pick it up if you don't have it.
J. J. Horner 
CISSP,CCNA,CHSS,CHP,blah,blah,blah

Replies are listed 'Best First'.
Re^2: The purpose of prototypes in perl subroutines
by Joost (Canon) on Apr 13, 2005 at 15:31 UTC
    That's not prototyping: that's just predeclaring that the subroutine mysub exists. You're explicitly not specifying a prototype there.

    You can call any subroutine without parentheses as long as it's been "seen" before:

    #!/usr/local/bin/perl -w use strict; sub bla { print "Bla!\n"; } bla;
    update: Ironically, a nice way to make the above fail is to use a (wrong) protoype:
    #!/usr/local/bin/perl -w use strict; sub bla($) { print "Bla!\n"; } bla; __END__ syntax error at test.pl line 8, near "bla;" Execution of test.pl aborted due to compilation errors.
      It is the same thing. Ask Nat Torkington, as that is what he calls it. Probably pure semantics, but either way, it is considered prototyping.
      J. J. Horner 
      CISSP,CCNA,CHSS,CHP,blah,blah,blah
      

        Just because someone says something doesn't make it true. This isn't just semantics, either.

        Perhaps you give us the reference where you found Nat talking about this sort of prototype (article name or page number would work). IF you are talking about the "Cryptocontext" article, I think you've misunderstood something.

        --
        brian d foy <brian@stonehenge.com>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-03-28 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found