in reply to help required on modifying a file content
outputsuse strict; use warnings; my @hdr; my @val; for (;;) { my $hdr_line_in = <DATA>; last unless defined $hdr_line_in; my $val_line_in = <DATA>; last unless defined $val_line_in; chomp($hdr_line_in, $val_line_in); while ($hdr_line_in =~ /(\S+)/g) { my $hdr = lc($1); my $skip = $-[1]; my $val = $val_line_in =~ /^.{$skip}(\S*)/ ? $1 : ''; push(@hdr, $hdr); push(@val, $val); } last unless defined <DATA>; } print(join(',', @hdr), "\n"); print(join(',', @val), "\n"); __DATA__ A1 9198 B1 C1 D1 E1 F1 23 232 233 G1 H1 I1 2222 323
a1,b1,c1,d1,e1,f1,g1,h1,i1 9198,23,232,,,233,2222,,323
I assumed the data contained spaces, not tabs.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: help required on modifying a file content
by Bharath (Novice) on Nov 17, 2005 at 10:23 UTC | |
by ikegami (Patriarch) on Nov 17, 2005 at 18:21 UTC |