Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: hash of arrays of arrays

by Cristoforo (Curate)
on Aug 23, 2012 at 23:06 UTC ( #989404=note: print w/replies, xml ) Need Help??

in reply to hash of arrays of arrays

I believe philiprbrenan found your problem. Every time you found an entry with a new '$clean' key, you were wiping out the other entries in the hash with: %duplicates = ($clean => [$equ, $pmf, $pro, $serial, $usr, $date]);

Here is a code similiar to your problem that prints the duplicates.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %duplicates; my $serials = [ [qw/ foo bar serial1 /], [qw/ who now serial2 /], [qw/ one more serial2 /], [qw/ two end serial3 /] ]; for my $row (@$serials) { my $clean = $row->[2]; push @{$duplicates{$clean}}, $row; } print Dumper \%duplicates; for my $clean (keys %duplicates) { my $aref = $duplicates{$clean}; if (@$aref > 1) { # if duplicates for my $row (@$aref) { print "@$row\n"; } } }

C:\Old_Data\perlp>perl $VAR1 = { 'serial3' => [ [ 'two', 'end', 'serial3' ] ], 'serial1' => [ [ 'foo', 'bar', 'serial1' ] ], 'serial2' => [ [ 'who', 'now', 'serial2' ], [ 'one', 'more', 'serial2' ] ] }; who now serial2 one more serial2

Update: Don't know why I pulled $clean out. This version doesn't.

Replies are listed 'Best First'.
Re^2: hash of arrays of arrays
by tnyflmngs (Acolyte) on Aug 24, 2012 at 02:21 UTC
    Thanks both of you. I have seen people on here talking about Data::Dumper, guess I should make the time to mess with it. I will take a look at it in the morning. I guess I thought that...who knows what I thought, it seems silly as I say it out loud. For some reason I thought that I had to be careful not to clobber my hash, but it appears that is exactly what I tried to do.
      As another suggestion, this $$xx[blah] notation is confusing. Here $row is a reference. I prefer the arrow notation. This makes it more clear that $row is a reference.
      for my $row ( @{$serials}) { my $equ = $row->[$equIndex]; my $pmf = $row->[$pmfIndex]; my $pro = $row->[$proIndex]; my $serial = $row->[$serialIndex]; my $usr = $row->[$usrIndex]; my $date = $row->[$dateIndex]; my $clean = $row->[$cleanIndex]; #blah..... }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989404]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2018-04-25 20:32 GMT
Find Nodes?
    Voting Booth?