in reply to column counter and printf question
use strict; use warnings; while( my $line = <DATA>) { next unless $. > 12; # $. contains current line number next if $line =~ /^$/; # skip blank lines chomp $line; # remove end-of-line character $line =~ s/\s+//; # strip leading whitespace my @columns = split(/\s+/, $line); # split columns on whitespace my $format = "%8.3f" . "%10.3f"x(@columns-3) . "\n"; printf $format, @columns[2..$#columns]; } # my guess at the input data __DATA__ SKIP 1 SKIP 2 SKIP 3 SKIP 4 SKIP 5 SKIP 6 SKIP 7 SKIP 8 SKIP 9 SKIP 10 SKIP 11 SKIP 12 Line_1 0.0 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 Line_2 0.0 0.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 Line_3 0.0 0.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 1.0 Line_4 0.0 0.0 4.0 5.0 6.0 7.0 8.0 9.0 1.0 2.0 Line_5 0.0 0.0 5.0 6.0 7.0 8.0 9.0 1.0 2.0 3.0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: column counter and printf question
by Anonymous Monk on Oct 28, 2015 at 15:30 UTC | |
by scorpio17 (Canon) on Oct 28, 2015 at 17:23 UTC | |
|
Re^2: column counter and printf question
by fasoli (Beadle) on Oct 28, 2015 at 15:53 UTC | |
by BillKSmith (Monsignor) on Oct 28, 2015 at 20:51 UTC | |
by fasoli (Beadle) on Oct 29, 2015 at 12:22 UTC | |
by Athanasius (Cardinal) on Oct 29, 2015 at 12:53 UTC | |
by fasoli (Beadle) on Oct 29, 2015 at 14:45 UTC | |
by GotToBTru (Prior) on Oct 29, 2015 at 14:45 UTC | |
by ww (Archbishop) on Oct 28, 2015 at 18:25 UTC |