subroutines may be located anywhere in the main program

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default subroutines may be located anywhere in the main program

    Perlsub says subroutines may be located anywhere in the main program;
    and indeed,
    $ perl -e 'if(0){sub x{print "wow"}};x;'
    wow

    Anything non ideal here?
    Dan Jacobson Guest

  2. Similar Questions and Discussions

    1. Question about subroutines....
      Hi, Is it possible to write a subroutine in Perl which accepts an open file handle as parameter? At the moment it seems hopeless, but is it? ...
    2. Making A Library of Perl Subroutines
      I am writing several subroutines that I want to make available to other programs without directly including the code in those programs. Can anyone...
    3. DBConn.asp -- database subroutines
      Hey guys :) I was just hoping a couple of you could let me know what you think about my DBConn.asp script on my website. you can view the code...
    4. using Getopt with subroutines
      Hello, I have a subroutine that is contained within its own module and package. It currently takes 7 different arguments, but only 2 of them are...
    5. Undefined subroutines in my modules
      I have three modules in my site_perl directory Vertigan::File, Vertigan::Template and Vertigan::Datafile. Both Template and Datafile call File...
  3. #2

    Default Re: subroutines may be located anywhere in the main program

    Also sprach Dan Jacobson:
    > Perlsub says subroutines may be located anywhere in the main program;
    > and indeed,
    > $ perl -e 'if(0){sub x{print "wow"}};x;'
    > wow
    >
    > Anything non ideal here?
    Readability perhaps. At least I'd be confused to see a subroutine
    declared in an if-branch.

    Other than that, there is not much wrong with it as long as you don't
    expect to impose a certain scope or visibility on your subroutines.
    They'll always be globally accessible (within the same package) and Perl
    doesn't know about inner functions or so.

    Tassilo
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval Guest

Posting Permissions

  • You may not post new threads
  • You may 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