On Sat, 2008-04-05 at 00:37 +0800, Jeff Pang wrote:
> On Fri, Apr 4, 2008 at 11:42 PM,  <[EMAIL PROTECTED]> wrote:
> > use constant PART_NUMBER            => 'P/N';
> >
> >  print PART_NUMBER;
> >
> >  The above prints, "P/N", as I would expect.  Later in the script I
> >  want to access a hash value using the constant like this:
> >  my $part = $parts{ $key }{ PART_NUMBER }; <- this doesn't work, but
> 
> because the hash think "PART_NUMBER" is a key name instead of a constant.
> to avoid this confusion, add a "+" before the constant,
> 
> my $part = $parts{ $key }{ +PART_NUMBER };

Is there any real advantage of 

use constant PART_NUMBER => 'P/N';
over 
my $PART_NUMBER = 'P/N';

Yes I know that it can be modified but conventions such as upper case
constants can almost remove that problem.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to