Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: refs and hashes

by Ay_Bee (Monk)
on Jul 29, 2002 at 14:10 UTC ( [id://185984]=note: print w/replies, xml ) Need Help??


in reply to refs and hashes

This piece of code seems suspect to me
# find all the entities in the current file if (/entity\s+(\w+)\s+is/i) { $1{'name'} = $1; $1{'fname'} = $vhd_file; push @entities, \%1; }
I think it should be something like
push @entities, \%{$1};
perhaps using the Data::Dumper module would help to debug it, also I would use a hash of hashes rather than a separate hash for each entity.
use Data::Dumper; .... # find all the entities in the current file if (/entity\s+(\w+)\s+is/i) { $hash{$1}{'name'} = $1; $hash{$1}{'fname'} = $vhd_file; push @entities, $1; } .... close VHD; } print Dumper(%hash);
Hope this is of some use Ay_Bee
-_-_-_-_-_-_-_-_-_-_-_- My memory concerns me - but I forget why !!!

Replies are listed 'Best First'.
Re: Re: refs and hashes
by dragonchild (Archbishop) on Jul 29, 2002 at 14:32 UTC
    push @entities, \%{$1};

    This is not desirable, because this uses a soft reference, which is a (generally) "Bad Thing"(tm), for a host of reasons.

    Best is to use a lexically-scoped hash or a HoHoH's (like the poster has ended up doing).

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://185984]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-16 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found