in reply to Pretty-Print Table (Omitting Duplicates)

I don't see how remembering the last line becomes "increasingly ugly":

use strict; my @lines = map { [split /,/] } split /\s+/, <<CSV; Desk,Left-Drawer,Paperclips Desk,Left-Drawer,Pens Desk,Right-Drawer,Ruler Filing-Cabinet,Top-Drawer,Files CSV my @last_line; for my $line (@lines) { my $i = 0; $i++ while $line->[ $i ] eq $last_line[ $i ]; # Now, empty out the elements we don't want to output again # and copy over the rest of @$line my @output = (('') x $i, @{$line}[$i..$#$line]); # Output through table module of your choice print join "|", map {sprintf "%-20s",$_} @output; print "\n"; @last_line = @$line; };

The uglyness stays the same no matter what your column count is.

Replies are listed 'Best First'.
Re^2: Pretty-Print Table (Omitting Duplicates)
by Anonymous Monk on Apr 24, 2011 at 09:56 UTC

    Thanks. Rather naïvely I was thinking I would have to hard-code each column’s comparison in which is why I thought it would become ugly after a while.