#!/usr/bin/env perl # # paths2tree - convert paths (e.g. of files) to a tree-like representation # # $Id$ use warnings; use strict; use Getopt::Std; use Text::CSV_XS; my %opt; getopts( 'hs:t:', \%opt ); &help if $opt{'h'}; my $sep = $opt{'t'} // '/'; my $tab = $opt{'s'} // ' '; @ARGV or @ARGV = ('-'); my $csv = new Text::CSV_XS( { sep_char => $sep, eol => $/ } ) or die "cannot initialize CSV parser (not installed?)\n"; my $prev_row = []; while ( my $row = $csv->getline(*ARGV) ) { my $still_equal = 1; for ( my $i = 0 ; $i < @$row ; ++$i ) { $still_equal &= $i < @$prev_row && $row->[$i] eq $prev_row->[$i]; if ( !$still_equal ) { printf "%s%s\n", $tab x $i, $row->[$i]; } } $prev_row = $row; }