develooper Front page | perl.beginners | Postings from March 2002

urgent redundancy question

Thread Next
M z
March 4, 2002 12:19
urgent redundancy question
Message ID:

I'm trying to remove to analyze two successive lines
in a row and remove one of them if they say the same
thing, like so...based on different beginning

sample input:

B water
C water

if so, then only keep B water and discard C water

I tried doing so with this snippet, but it wasn't
exactly working as scheduled

I thought I would force analysis after the one time
through the while, before the variables were changed
in the second iteration of the while, but this was
printing them way too many times!!!  can someone
please help an otherwise distressed individual.

while(<I>) {

     $b =~ s/B //;
     $c =~ s/C //;

     if ($b eq $c) {
     print "B $b";
     elsif ($b ne $c) {
     print "B $b\n";
     print "C $c\n";

     if (/^B .*/) {
     $b = $_;

      elsif (/^C .*/) {
      $c = $_;


Do You Yahoo!?
Yahoo! Sports - sign up for Fantasy Baseball

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About