SPUG: declarations

Greg McCarroll greg at mccarroll.demon.co.uk
Mon Jan 1 08:12:16 CST 2001


* Dave Cross (dave at dave.org.uk) wrote:
> At 02:17 01/01/2001, Greg McCarroll wrote:
> >* David H. Adler (dha at panix.com) wrote:
> > >
> > > My question is, why would you even have a line of code like this in a
> > > program at a point where %in wouldn't already exist?  And if you
> > > localize it as at top, you're effectively just assinging a value of
> > > undef to $one_server.
> >
> >based on a few leaps of logic, is the question - how do i set a default
> >for $in{'server'} if its not already defined. if this isn't the real
> >question please forgive me, but i'm just joining into the guessing game
> >along with everyone else ....
> >
> >anyway the neatest way to declare the defaults just before they are
> >used is (imho),
> >
> >$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 ;-)

-- 
Greg McCarroll                          http://www.mccarroll.uklinux.net

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list