Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] Ampersand sign pre-fix on calling of a sub-routine

Expand Messages
  • Bobby Jafari
    Using & means that it s a user defined subroutine. For example: &print is a user define print and will not use Perls print function. Also, if you don t specify
    Message 1 of 5 , Feb 5, 2006
    • 0 Attachment
      Using & means that it's a user defined subroutine. For example:

      &print is a user define print and will not use Perls print function.
      Also, if you don't specify the "&", subroutines must be defined before
      you make a call to it.

      -----Original Message-----
      From: perl-beginner@yahoogroups.com
      [mailto:perl-beginner@yahoogroups.com] On Behalf Of Frank Kleinburg (el
      Oso de Tejas)
      Sent: Monday, 6 February 2006 14:48
      To: perl-beginner@yahoogroups.com
      Subject: [PBML] Ampersand sign pre-fix on calling of a sub-routine

      Hello oh keepers of perl knowledge, I have a simple question for which
      an explanation has eluded me so far in my searching in any of the perl
      books I do have..

      In reading a lot of perl scripts here at work for which I am tasked to
      maintain, I see a lot of ampersand signs (&) in front of called
      subroutine names.. For example from some recent code at which I looked:

      # --------------------------------------------------------#
      &ReadConfigFile();
      &ReadProductionDatabases();
      &CheckPrevDbChk();
      &printScreen($Name, $Purpose, $ManualCheck) if ! $PROFILE_NAME;
      &parseOratab();
      &checkDatabases();
      &myexit;

      sub myexit
      [snip]

      Will someone take a moment and explain this?? Thanks in advance.. flk k




      Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html
      Yahoo! Groups Links
    • Frank Kleinburg (el Oso de Tejas)
      ... Bobbie, Thanks for the explanation.. And I do like what it does.. Nice way to keep things straight.. But the last bit has me confused.. I place my
      Message 2 of 5 , Feb 5, 2006
      • 0 Attachment
        At 10:22 PM 2/5/2006, you wrote:
        >Using & means that it's a user defined subroutine. For example:
        >
        >&print is a user define print and will not use Perls print function.
        >Also, if you don't specify the "&", subroutines must be defined before
        >you make a call to it.

        Bobbie,
        Thanks for the explanation.. And I do like what it does.. Nice way to
        keep things straight..

        But the last bit has me confused.. I place my subroutines at the end of my
        code.. So far my code works well and I have no trouble calling them from
        within the program.. So am I assuming this is not what you mean in your
        post about the subroutines must be defined before they are called??

        Thanks again for ya'lls time.. It's great having such wonderful shoulders
        on which I can stand..

        flk k
      • Bobby Jafari
        My understanding of it is: If you are using & - placing the subroutines at the end of the file will work. If you don t use & - then you must define the
        Message 3 of 5 , Feb 5, 2006
        • 0 Attachment
          My understanding of it is:

          If you are using & - placing the subroutines at the end of the file will
          work.
          If you don't use & - then you must define the subroutines first.
        • John J. Francini
          Subroutines needn t be defined before they are used. You can, if you want, pre-declare them to save a little time on the part of the compiler. It will find
          Message 4 of 5 , Feb 5, 2006
          • 0 Attachment
            Subroutines needn't be defined before they are used. You can, if you
            want, pre-declare them to save a little time on the part of the
            compiler. It will find them all anyway.

            Do you have the O'Reilly Perl book set (or the Perl CD library)?
            Highly recommended -- especially since the authors are usually DEEPLY
            involved in the development of Perl itself.

            John


            >At 10:22 PM 2/5/2006, you wrote:
            >>Using & means that it's a user defined subroutine. For example:
            >>
            >>&print is a user define print and will not use Perls print function.
            >>Also, if you don't specify the "&", subroutines must be defined before
            >>you make a call to it.
            >
            >Bobbie,
            > Thanks for the explanation.. And I do like what it does.. Nice way to
            >keep things straight..
            >
            >But the last bit has me confused.. I place my subroutines at the end of my
            >code.. So far my code works well and I have no trouble calling them from
            >within the program.. So am I assuming this is not what you mean in your
            >post about the subroutines must be defined before they are called??
            >
            >Thanks again for ya'lls time.. It's great having such wonderful shoulders
            >on which I can stand..
            >
            >flk k
            >
            >
            >
            >
            >Unsubscribing info is here:
            >http://help.yahoo.com/help/us/groups/groups-32.html
            >Yahoo! Groups Links
            >
            >
            >
            >

            --
            ----
            John Francini <mailto:francini@...>
            +---------------------------------------------------------------------------+
            | "I have come to the conclusion that one useless man is called a disgrace; |
            | that two are called a law firm; and that three or more become a Congress.|
            | And by God I have had _this_ Congress!" |
            | -- John Adams |
            +---------------------------------------------------------------------------+
          • merlyn@stonehenge.com
            ... Bobby My understanding of it is: Bobby If you are using & - placing the subroutines at the end of the file will Bobby work. Bobby If you don t use & -
            Message 5 of 5 , Feb 6, 2006
            • 0 Attachment
              >>>>> "Bobby" == Bobby Jafari <bobby.jafari@...> writes:

              Bobby> My understanding of it is:
              Bobby> If you are using & - placing the subroutines at the end of the file will
              Bobby> work.
              Bobby> If you don't use & - then you must define the subroutines first.


              later; # doesn't work
              later(); # works
              &later; # works
              &later(); # works
              sub later { }

              sub chomp { }
              chomp; # calls built-in chomp
              chomp(); # calls built-in chomp
              &chomp; # calls your chomp
              &chomp(); # calls your chomp

              So & identifies the word as a user-defined subroutine, as opposed to a
              bareword or a built-in. It's only necessary when it would be otherwise
              misinterpreted.

              --
              Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
              <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
              Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
              See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
            Your message has been successfully submitted and would be delivered to recipients shortly.