Professional Web Applications Themes

PROTO in sub NAME (PROTO) { - PERL Beginners

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/...

  1. #1

    Default PROTO in sub NAME (PROTO) {

    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/

    Jeremy Guest

  2. #2

    Default Re: PROTO in sub NAME (PROTO) {

    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::Dep
    -Data::Dumper
    -Clone
    -Perl::Tidy
    -Beautifier
    -DBD::SQLite

    WilliamGunther@aol.com Guest

  3. #3

    Default Re: PROTO in sub NAME (PROTO) {

    On Sep 21, Jeremy Kister said:
     

    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 doentation 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

    Jeff Guest

Similar Threads

  1. Replies: 0
    Last Post: November 8th, 09:46 PM
  2. #39220 [NEW]: type in html.c proto declaration
    By jeffg at activestate dot com in forum PHP Bugs
    Replies: 3
    Last Post: October 20th, 09:09 PM
  3. Replies: 0
    Last Post: September 25th, 10:59 AM
  4. [PHP-DEV] Fwd: [PATCH] proto fix php_imap.c
    By Chuck Hagenbuch in forum PHP Development
    Replies: 1
    Last Post: November 13th, 08:55 PM
  5. proto-type sub needs new ribbon ?
    By stu7 in forum PERL Miscellaneous
    Replies: 1
    Last Post: August 22nd, 01:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139