in reply to Re^2: tab delimited extraction, formatting the output
in thread tab delimited extraction, formatting the output
Note that in order to get the formatting, you need to cache the previous string in order to determine the indentation.
#!/usr/bin/perl use strict; use warnings; use Text::CSV; #my $file = "fielded.txt"; my $csv = Text::CSV->new({sep_char => "\t"}); # create a new objec +t open my $fh, "<", $file or die "Unable to open $file: $!"; my($u_value, $p_value, $mc_value) = (undef) x 3; while (my $data_ref = $csv->getline($fh)) { my @data = @{$data_ref}; if ($data[0] eq "'EOU'.") { ($u_value, $p_value, $mc_value) = (undef) x 3; print "\n"; } elsif ($data[2] eq "u") { $u_value = $data[3]; print "\n$u_value"; undef $p_value; } elsif ($data[2] eq "p") { if ($p_value) { print "\n" . ' ' x length $u_value; } $p_value = $data[3]; print "\t$p_value"; undef $mc_value; } elsif ($data[2] eq "mc") { if ($mc_value) { print "\n" . ' ' x length $p_value; } $mc_value = join("\t",@data[7 .. 11]); print "\t$mc_value"; } else { #die "Unexpected line format encountered, $file, @data"; } } close $fh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: tab delimited extraction, formatting the output
by Anonymous Monk on Feb 09, 2009 at 23:20 UTC | |
by kennethk (Abbot) on Feb 09, 2009 at 23:28 UTC | |
by zzgulu (Novice) on Feb 12, 2009 at 15:47 UTC | |
by kennethk (Abbot) on Feb 12, 2009 at 15:59 UTC | |
by zzgulu (Novice) on Feb 12, 2009 at 18:31 UTC | |
|