in reply to Re^2: Combining 3 files
in thread Combining 3 files
That is easy, the line is confusing :)
It is also confusing $dataset for a hashref
is likemy @results = ( $col[0], $col[3] ); for my $dataset (@data) { push @results, ( sort { my $diff_a = $col[2] - $a->[1]; $diff_a *= -1 if $diff_a < 0; my $diff_b = $col[2] - $b->[1]; $diff_b *= -1 if $diff_b < 0; $diff_a <=> $diff_b; } @{ $dataset->{ $col[0] } } )[0]->[2]; }
is likemy @results = ( $col[0], $col[3] ); for my $dataset (@data) { my ( $first ) = sort { my $diff_a = $col[2] - $a->[1]; $diff_a *= -1 if $diff_a < 0; my $diff_b = $col[2] - $b->[1]; $diff_b *= -1 if $diff_b < 0; $diff_a <=> $diff_b; } @{ $dataset->{ $col[0] } } push @results, $first->[2]; }
my @results = ( $col[0], $col[3] ); for my $dataset (@data) { my @beef = @{ $dataset->{ $col[0] } }; @beef = sort { my $diff_a = $col[2] - $a->[1]; $diff_a *= -1 if $diff_a < 0; my $diff_b = $col[2] - $b->[1]; $diff_b *= -1 if $diff_b < 0; $diff_a <=> $diff_b; } @beef; push @results, $beef[0]->[2]; }
$a and $b are globals, they're how sort works
Is it still confusing?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Combining 3 files
by garyboyd (Acolyte) on Jun 27, 2011 at 09:11 UTC | |
by Anonymous Monk on Jun 27, 2011 at 10:27 UTC | |
by garyboyd (Acolyte) on Jun 27, 2011 at 14:47 UTC | |
by Anonymous Monk on Jun 27, 2011 at 14:58 UTC | |
by garyboyd (Acolyte) on Jun 27, 2011 at 15:11 UTC | |
|