Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Question regarding variable scope

by hanenkamp (Pilgrim)
on Oct 17, 2003 at 02:34 UTC ( [id://299925]=note: print w/replies, xml ) Need Help??


in reply to Question regarding variable scope

This is being a little picky, but I noted you used:

sub find_pairing($white_player){ ... }

in the code snippet. This prototype will work, but isn't strictly correct. It would be better to say:

sub find_pairing($) { ... }

I also noted that some of the replies used:

sub find_pairing() { my $white_player = shift; ... }

This is bad. If you call this method after this declaration, then a call like find_pairing("Bob") will fail because the prototype will accept no arguments. It would be better to say nothing about the signature of the subroutine like:

sub find_pairing { ... }

Anyway, you're all probably aware of this, but I wanted to make sure the casual browser, who might not, knows the difference between these slight variations. I look forward to Perl 6, where this cruft will be cleaned up.

Replies are listed 'Best First'.
Re: Re: Question regarding variable scope
by MarkM (Curate) on Oct 17, 2003 at 05:36 UTC

    Better yet, avoid the use of prototypes altogether in Perl. They are broken when it comes to actual programmer expectations. $ means "force scalar context" not "expect a scalar". Note that find_pairing(@list) does not generate a compile time error, but will generate perhaps-unexpected runtime behaviour.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found