in reply to Hashes and Memory

Hum -- this looks odd

my %coord = %{$ref_coord}; #dereference

Doesn't that copy the hash?

It's probably better to use the reference directly. Something like :-

#e.g. my @c = split /\s+/,$ref_coord->{$id};

Replies are listed 'Best First'.
Re^2: Hashes and Memory
by Jeri (Scribe) on Sep 08, 2011 at 17:24 UTC

    Does it copy the hash? I'm still rather new at perl (just 1 year experience). This could mostly likely be a novice error.

    How does your code work?  my @c = split /\s+/,$ref_coord->{$id};

    Does it create an array based on the space between the coordinates in the hash value? and what does the "->" mean exactly?

      Actually, I understand it.

      My question is how can I put the coordinates in @c if the hash has not been dereferenced? or am I doing (and thinking) about this all wrong?

        You don't need to dereference the hash ref into a standard hash variable to use it. As the previous poster said, this will make a copy of the hash instead of editing the original. You can use a hash ref just as you would a standard hash by dereferencing as needed. Below are comparisons of some common hash syntax.

        Hash Hash Ref my %hash = (key=>'value'); my $hash_ref = {key=>'value'}; $hash{key} = 'mod_value'; $hash_ref->{key} = 'mod_value'; print $hash{key}; print $hash_ref->{key}; my @keys = keys %hash; my @keys = keys %{$hash_ref};

        Have a look at perlreftut for the tutorial on references. That should tell you everything you need to know :)

        Got everything working! Thanks Everyone!