Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Is it there, or is it not?? Quirkiness with error handling.

by dmmiller2k (Chaplain)
on Jul 12, 2002 at 13:07 UTC ( [id://181254]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://181254]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-19 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found