in reply to Re: Is it there, or is it not?? Quirkiness with error handling.
in thread Is it there, or is it not?? Quirkiness with error handling.

"... please do not call subroutines using an ampersand. Write err3() rather than &err3()."

FYI: this is a special syntax. Calling a subroutine this way from within a subroutine has the effect of passing the (remaining) arguments to the inner sub that were passed to the outer. To wit:

# main outer( 1, qw( A Set of Args )); sub outer { my $pass = shift; &inner if $pass; } sub inner { print "inner: ", join( ' ', @_ ), "\n"; }

will print:

A Set of Args

dmm

If you GIVE a man a fish you feed him for a day
But,
TEACH him to fish and you feed him for a lifetime

Replies are listed 'Best First'.
(tye)Re: Is it there, or is it not?? Quirkiness with error handling.
by tye (Sage) on Jul 12, 2002 at 20:47 UTC

    Note that you are confusing &mysub; and &mysub(); which are very different. (tye)Re: A question of style goes into these in some detail.

    As for avoiding & on subroutine calls, that is, to a great extent, a style issue. Frankly, several of the reasons for using & on subroutine calls (avoid collisions with built-ins, stylistically distinguish user subs from built-ins, uniformity of sigils with other common user-defined items) are much more compelling to me than any of the reasons for not using them: "looks like Perl4" (big deal), "overrides prototypes" (don't use prototypes in most cases).

    So I strongly disagree with Aristotle on that point.

            - tye (but my friends call me "Tye")

      Whoops! That was a typo! Instead of removing the () from &mysub(), I did just the opposite and removed the &.

      In real code, the compiler usually catches stuff like this ... :)

      dmm