JayK's code samples
Given a 2d table - remove all empty columns
The following code searches a 2d hash (aka table) to determine if a particular column in every row is empty. It has the advantage of speeding up as it works because once it determines that a column is not empty for one row, it will never check that column again.
my %empty_columns = map { $_ => 1 } @column_names; foreach my $row (keys %table) { foreach my $column (keys %empty_columns) { if ($table{$row}->{$column} ne '') { delete($empty_columns{$column}); } } } # don't bother to do the delete if we don't have if (keys %empty_columns) { foreach my $row ($keys %table) { foreach my $column (keys %empty_columns) { delete($table{$row}->{$column}); } } }
Showing changes from previous revision. Added | Supprimée
