Next | Program Repair Shop | 221 |
The next most prominent part of the program is
56 $chain1[$i] =~ s/0/L/g; $chain1[$i] =~ s/1/H/g;
57 $chain2[$i] =~ s/0/L/g; $chain2[$i] =~ s/1/H/g;
58 $chain3[$i] =~ s/0/L/g; $chain3[$i] =~ s/1/H/g;
59 $chain4[$i] =~ s/0/L/g; $chain4[$i] =~ s/1/H/g;
60 $chain5[$i] =~ s/0/L/g; $chain5[$i] =~ s/1/H/g;
61 $chain6[$i] =~ s/0/L/g; $chain6[$i] =~ s/1/H/g;
62 $chain7[$i] =~ s/0/L/g; $chain7[$i] =~ s/1/H/g;
63 print OUTFILE2 "\n(ct_so
64 $chain1[$i]$chain2[$i]$chain3[$i]$chain4[$i]$chain5[$i]$chain6[$i]$chain7[$i]
65 )";
Eliminating the family of variable names allows us to replace this with:
for (@chain) { $_->[$i] =~ s/0/L/g; $_->[$i] =~ s/1/H/g; } my @chars = map $_->[$i], @chain; print OUTFILE2 "\n(ct_so\n", join("", @chars), "\n)";
15 lines become 5
Next | Copyright © 2002 M. J. Dominus |