develooper Front page | perl.macperl | Postings from August 2005

Re: [MacPerl] using references with hashes

Thread Previous | Thread Next
From:
Joshua Juran
Date:
August 3, 2005 15:21
Subject:
Re: [MacPerl] using references with hashes
Message ID:
0a33e69bd3f77d41834925a1e51aa59d@metamage.com
On Aug 3, 2005, at 10:01 AM, Louis Pouzin wrote:

> To avoid cluttering scripts with intricate expressions I tried 
> references,
> with mixed results. e.g. instead of:
>
>    delete $H{one}{two}{three}[0]{four} if exists 
> $H{one}{two}{three}[0]{four};
>
> I'd prefer to write:
>    $ref = \$H{one}{two}{three}[0]{four};
>    delete $$ref if exists $$ref; # or somesuch.
>
> While I could get each, keys, and values, out of references, I haven't 
> figured
> out a working syntax for exists, delete, and growing hashes.
>
> Perhaps someone could suggest a right way. Thanks.

my $ref = \$H{one}{two}{three}[0];
# Either of these should work
delete %$ref{four} if exists %$ref{four};
delete $ref->{four} if exists $ref->{four};

But there may be a clearer way to design the code in the first place.

Josh

-- 
Joshua Juran
Metamage Software Creations - Mac Software and Consulting
http://www.metamage.com/

                * Creation at the highest state of the art *



Thread Previous | Thread Next


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