Next Program Repair Shop 291

Avoid Families of Variable Names

         my $section = 0;  my @sectone;  my @secttwo;
         while(<TEXTFILE>) {
             if (/;section1/) {
                 $section = 1;
             } elsif (/;section2/) {
                 $section = 2;
             } else {
                 if ($section == 1) {
                     push(@sectionone, $_);
                 } elsif ($section == 2) {
                     push(@sectiontwo, $_);
                 } else {
                     print "No section defined for: $_\n";
                     }
                 }
             }
         my $section = 0;  my @sects; 
         while(<TEXTFILE>) {
             if (/;section([12])/) {
                 $section = $1;
             } elsif ($section) {
                 push @{$sects[$section]}, $_;
             } else {
                 print "No section defined for: $_\n";
             }
         }


Next Copyright © 2002 M. J. Dominus