develooper Front page | perl.beginners | Postings from December 2002

Re: Constants and Hash Question

Thread Previous
From:
Rob Dixon
Date:
December 11, 2002 06:41
Subject:
Re: Constants and Hash Question
Message ID:
002801c2a123$8b731ea0$53a77ad5@home

----- Original Message -----
From: "Paul Kraus" <pkraus@pelsupply.com>
To: "Perl" <beginners@perl.org>
Sent: Wednesday, December 11, 2002 2:16 PM
Subject: Constants and Hash Question


> I am declaring my constants like this.
> use constant SOURCE => "/path/folder/"
> Now how would I use this constant is a print statement or any statement
> for that matter.
> print "$SOURCE" does not work and of course print "source" will not
> work.
>

    print SOURCE;

>
> I understand that this works but I do not understand what its doing and
> the need for the parenthesis.
> Could someone explain this statement for me. I have put <> around the
> part I don't understand.
>
> this is part of a tied hash for Config::IniFiles.
> --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> while (($k,$v) = each <%{$ini{$section}}>)
>

%ini is a hash being referenced by scalar $section. The hash values are
references to other hashes, so $ini{$section} is a hash reference. This must
be enclosed in a block before it is dereferenced to a hash, as
%$ini{$section} would try to dereference scalar $ini (which doesn't exist)
as a hash. So we have %{ $ini{$section} }.

HTH,

Rob



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About