in reply to Weirdness with pushing records, and values saved

ultranerds:

Ok, what's the problem with it? The $VAR1->{'13.704011,-89.247029'}[0] is (if I understand correctly) simply Data::Dumper's way of telling you that the first item in the array referenced by $VAR1->{'13.709931,-89.202365'} is the same item as the first item in the array referenced by $VAR1->{'13.704011,-89.247029'}. For example:

$ cat 887880.pl #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $t1 = {a=>1, b=>2, c=>3}; my $t2 = {a=>2, b=>5, c=>7}; my %H = ( X=>$t1, Y=>$t1, Z=>$t2 ); $H{Y}{b}=11; print Dumper(\%H); $ perl 887880.pl $VAR1 = { 'Z' => { 'c' => 7, 'a' => 2, 'b' => 5 }, 'X' => { 'c' => 3, 'a' => 1, 'b' => 11 }, 'Y' => $VAR1->{'X'} }; $

If that's intended, then everything is fine. If it's not intended, then perhaps you're building $link incorrectly and re-using a hash, and overwriting your data as shown above. I can't see how you're building $link, nor how you're accessing the data, so I can't tell quite what your problem is.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: Weirdness with pushing records, and values saved
by ultranerds (Hermit) on Feb 13, 2011 at 20:11 UTC
    Hi,

    aaah ok - that makes sense - not sure why its doing that though =) I ended up using a slight variation of the code now:
    if (length $link->{LatitudLongitud} > 5) { if (!$seen->{$link->{LatitudLongitud}}) { push @{$records->{$link->{LatitudLongitud}}}, $link->{ +ID}; $seen->{$link->{LatitudLongitud}} = 1; # make sure we +set this, so we know its been seen already! } else { push @{$records->{$link->{LatitudLongitud}}}, $link->{ +ID}; } } if (length $link->{LatitudLongitud02} > 5 && $link->{LatitudLo +ngitud} ne $link->{LatitudLongitud02}) { if (!$seen->{$link->{LatitudLongitud02}}) { push @{$records->{$link->{LatitudLongitud02}}}, $link- +>{ID}; $seen->{$link->{LatitudLongitud02}} = 1; # make sure w +e set this, so we know its been seen already! } else { push @{$records->{$link->{LatitudLongitud02}}}, $link- +>{ID}; } } $links->{$link->{ID}} = $link;
    ..and then after that, looping through it with this:
    map { my ($lat,$long) = split ",", $_; my @links = @{$records->{$_}}; my $box_contents; my @html_contents; my $num_links = $#links+1; foreach (@links) { my $link = $links->{$_}; # do stuff here } } keys %$seen;
    ..and that works like a charm :)

    Thanks again for the reply - its always good to know the reason behind these things, just in case I come across the same thing again in the future :)

    Cheers

    Andy