vendredi 1 mai 2015

Perl Output from File error

Assuming the following input:

        for ($k = 0; $k < @tableb; $k++) {
        chomp ($tableb[$k]);
        ($netsta, $delay_time) = (split /\s+/,$tableb[$k])[1,9];
        ($net, $sta) = (split /\./, $netsta)[0,1];
        print $net, " ", $sta, "\n";
        if ($net eq "ZJ" && $sta eq "DONT") {
                $stat = 1;
            } elsif ($net eq "ZJ" && $sta eq "MICH") {
                $stat = 2;
            } elsif ($net eq "ZJ" && $sta eq "LEON") {
                $stat = 3;
            } elsif ($net eq "ZJ" && $sta eq "RAPH") {
                $stat = 4;
            } elsif ($net eq "ZJ" && $sta eq "SPLN") {
                $stat = 5;
            } elsif ($net eq "ZJ" && $sta eq "SHRD") {
                $stat = 6;
            } elsif ($net eq "ZJ" && $sta eq "CASY") {
                $stat = 7;
            } elsif ($net eq "ZJ" && $sta eq "APRL") {
                $stat = 8;
            } elsif ($net eq "ZJ" && $sta eq "FOOT") {
                $stat = 9;
            } elsif ($net eq "ZJ" && $sta eq "BEBP") {
                $stat = 10;
            } elsif ($net eq "ZJ" && $sta eq "RKST") {
                $stat = 11;
            } elsif ($net eq "ZJ" && $sta eq "DUBY") {
                $stat = 12;
            } elsif ($net eq "ZJ" && $sta eq "SAMH") {
                $stat = 13;
            } elsif ($net eq "ZJ" && $sta eq "GRAW") {
                $stat = 14;
            } elsif ($net eq "ZJ" && $sta eq "KNYN") {
                $stat = 15;
            } else {

            }
        printf OUT "%s \n", $stat;

    }

I wish to take an output of net(network) and sta(station) from one file (As shown below), and then change the sta (station name indicated in the if/elsif conditionals), to a specific number (1-15). My output, though not only prints numbers for the stations, but it prints out a 5 as well, most likely corresponding to the other lines outputted in 0 and 1. I don't want the extra fives. I just want the station numbers changed.

Aucun commentaire:

Enregistrer un commentaire