in reply to how to compare the rows in a 2d array
What is the rule for printing? Maybe you want the following:
my @last_key; for my $row (@$arr_ref) { local $" = "\0"; my @curr_key = @{$row}[0,1]; if ("@curr_key" ne "@last_key") { { @last_key = @curr_key; print join "\n", @curr_key; print "$row->[2]\n"; } else { print ",", $row->[2]; }; };
There is one problem with my solution. I was too lazy to shield the code against \0 occurring in your data. If that is a possibility, you will have to modify my code to do a comparison by-element instead of relying on Perls stringification of arrays to do the magic.
|
|---|