in reply to Re: help required on modifying a file content
in thread help required on modifying a file content

Thanks for the reply. But in the code i have given only one unit. i.e. A1-I1 is one unit. There are many such units like A2-I2, A3-I3. required formatted text is one below the other. i.e. A1-I1 occupies 6 lines, A2-I2 occupies from 4-l2 lines,and so on. How can I make the code repetitive for every unit. Thanks in advance
  • Comment on Re^2: help required on modifying a file content

Replies are listed 'Best First'.
Re^3: help required on modifying a file content
by ikegami (Patriarch) on Nov 17, 2005 at 18:21 UTC
    use 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\d]+(\d+))/g) { my $hdr = lc($1); my $row = $2; my $skip = $-[1]; my $val = $val_line_in =~ /^.{$skip}(\S*)/ ? $1 : ''; push(@{$hdr[$row]}, $hdr); push(@{$val[$row]}, $val); } last unless defined <DATA>; } foreach my $row (0..$#hdr) { next unless defined $hdr[$row]; print(join(',', @{$hdr[$row]}), "\n"); print(join(',', @{$val[$row]}), "\n"); } __DATA__ A1 9198 B1 C1 D1 E1 F1 23 232 233 G1 H1 I1 2222 323 A2 B2 1234 5678
    outputs
    a1,b1,c1,d1,e1,f1,g1,h1,i1 9198,23,232,,,233,2222,,323 a2,b2 1234,5678