SPUG: declarations

Matt Tucker tuck at whistlingfish.net
Tue Jan 2 12:47:12 CST 2001

-- Greg McCarroll <greg at mccarroll.demon.co.uk> spake thusly:

> * Dave Cross (dave at dave.org.uk) wrote:
>> At 02:17 01/01/2001, Greg McCarroll wrote:
>> > $in{'server'} ||= 'default.mydomain.com';
>> > my $server = $in{'server'};
>> Or cut out the middle man and write:
>> my $server = $in{server} || 'default.mydomain.com';
> it all depends if you are playing perl golf or writing production
> code ;-)

Actually, I think I'd prefer the second method in either case. It has the advantage of not changing the inputs, so if for some reason you later wanted to know whether a server was specified, you still could.

Although it would probably be best (unless you're playing perl golf) to 

    use constant DEFAULT_SERVER => 'default.mydomain.com';
    my $server = $in{server} || DEFAULT_SERVER;

Alternately, if you were changing the inputs, it should be happening up 
by the getopts or readparse (or whatever you're doing) call; not down where it's used.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://mail.pm.org/archives/spug-list/attachments/20010102/6f1edd51/attachment.bin

More information about the spug-list mailing list