Professional Web Applications Themes

doubt in Definition of sub routine. - PERL Beginners

Hi All, I am using code written by some one else. I didn't understand the difference between these subroutines, the way they were defined. 1. sub addToLog { Some code } Any specific reason where we should not use braces ?? 2. sub displayEnv( ) { " } Any specific reason why we should use braces ?? 3. sub trim($) { " } Any specific reason why we should use a brace with a $ sign in it ?? Could some one specify reason when to use braces and when not to use . Replies are highly appreciated and thanks ...

  1. #1

    Default doubt in Definition of sub routine.

    Hi All,

    I am using code written by some one else. I didn't understand the difference
    between these subroutines, the way they were defined.

    1. sub addToLog { Some code } Any specific reason where we should
    not use braces ??
    2. sub displayEnv( ) { " } Any specific reason why we should
    use braces ??
    3. sub trim($) { " } Any specific reason why we should
    use a brace with a $ sign in it ??

    Could some one specify reason when to use braces and when not to use .
    Replies are highly appreciated and thanks in advance for your help.

    Regards
    Anand


    Anand Guest

  2. #2

    Default Re: doubt in Definition of sub routine.

    Anand V wrote: 

    That's already explained in the docs. Read about prototypes in
    "perldoc perlsub".

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Guest

  3. #3

    Default Re: doubt in Definition of sub routine.

    On Aug 5, Jose Alves de Castro said:
     

    It means that trim() expects ONE argument and will enforce scalar context
    on it. trim($foo) and trim(bar) both work.
     

    That has nothing to do with prototypes. That is only the case when trim()
    is defined before it's used (or before that specific use of the function).
     

    Not so; trim($) means it *must* have an argument sent to it.

    --
    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. a doubt
    By John W. Krahn in forum PERL Beginners
    Replies: 2
    Last Post: December 16th, 10:29 AM
  2. Some Doubt
    By Rob Dixon in forum PERL Beginners
    Replies: 0
    Last Post: December 12th, 07:31 PM
  3. 2nd doubt.
    By Paul Kraus in forum PERL Beginners
    Replies: 1
    Last Post: December 11th, 10:38 AM
  4. A doubt
    By mani in forum PERL Miscellaneous
    Replies: 2
    Last Post: September 25th, 08:49 PM
  5. When was Get Routine and Put Routine introduced
    By Rudolf Bargholz in forum IBM DB2
    Replies: 2
    Last Post: August 8th, 02:56 PM

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