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

urgent redundancy question

Thread Next
From:
M z
Date:
March 4, 2002 12:19
Subject:
urgent redundancy question
Message ID:
20020304201928.97672.qmail@web20903.mail.yahoo.com
Hi

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
charactes

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
http://sports.yahoo.com

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About