develooper Front page | perl.beginners | Postings from June 2007

Re: Passing arguments to subroutine

Thread Previous | Thread Next
Chas Owens
June 1, 2007 06:59
Re: Passing arguments to subroutine
Message ID:
On 31 May 2007 10:58:54 -0700, Paul Lalli <> wrote:
> On May 31, 10:15 am, (Yitzle) wrote:
> > I suspect one of the tutorials that Google or points to has
> > something in it that needs correcting.
> Actually, it's an unfortunate truth that up until Edition 3, the Llama
> itself recommended that you use the & to call subroutines...
> Paul Lalli

Alright, I am a pedantic jerk, but this struck as wrong.  I learned on
2nd edition Llama and Camel, so I dug up my old copies.  Learning Perl
2nd Edition says on page 92

    The subname is th name of the subroutine, which is any name like
    the names we've has for scalar variables, arrays, and hashes.  Once
    again, these come from a different namespace, so you can have a
    scalar variable $fred, an array @fred, a hash %fred, and now a
    subroutine fred*.

    * Technically, the subroutine's name is &fred, but you seldom need
to call it that.

Also, on page 93 it says

    Invoking a User Function
    You invoke a subroutine from within any expression by following
the subroutine
    name with parentheses, as in:

        say_hello();          # a simple expression
        $a = 3 + say_hello(); # part of a larger expression
        for ($x = start_value(); $x < end_value(); $x += increment()) {
        }                     # invoke three subroutines to define values

I checked Programming Perl (2nd Edition), just in case you meant the
Camel instead of the Llama, and it appears* to talk about subroutines
in the same was as perlsub currently does with no specific
recommendations about whether to use & or not (it just explains all of
the options and their side effects).

The Llama (2nd edition) was published in 1997.  That was ten years
ago.  You can see why I want to know where these people who are new to
Perl are being told to use & as part of the subroutine name.  I assume
there are some old tutorials out there (things live forever on the
Internet) and they are reading bad, old code at work.

* there may be a recommendation somewhere, but I couldn't find one in
my cursory glance through it.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About