sir, thank you
I tried this approach and it is almost perfect, can
you help me fix one thing...The problem is I negated
cases where is not a following C H20
such as
B H20
then its not printed, I don't want that, I wonder if
you can modify my script slightly to let those cases
be printed. The problem is that if I just insert a
print IOUT; statement under the
if (/^B .*/) {
$b = $_;
print IOUT $b;
}
then I will get repeating $b printing out...something
I don't want...please help!!
# to remove redundancy
print "Which file to remove redundant names from?\n";
$in = <STDIN>;
chomp($in);
open(I, "$in") || die "can't open file for reading:
($!)\n";
open(IOUT, ">test") || die "can't open file to write
to: ($!)\n";
while(<I>) {
if (/^B .*/) {
$b = $_;
}
elsif (/^C .*/) {
$c = $_;
$b =~ s/B //;
$c =~ s/C //;
if ($b eq $c) {
print IOUT "B $b";
}
elsif ($b ne $c) {
print IOUT "B $b";
print IOUT "C $c";
}
}
else {
print IOUT;
}
}
--- Wagner-David <[EMAIL PROTECTED]>
wrote:
> Here is one approach. Used __DATA__ to hold data
> for testing. Use dchomp to remove end of line.
>
> #!perl -w
> while(<DATA>) {
> chomp;
> next if ( /^\s*$/ ); # if blank line bypass
> if ( /^B/ ) {
> $b = $_;
> chomp($c = <DATA>);
> if ( $c !~ /^C/ ) {
> printf "Expecting pairs of B,C. Received
> C, but got the foloowing for\n";
> printf "the second record: <$c>\n";
> die "Correct and rerun";
> }
> }else {
> printf "Expecting pairs of B,C , but got
> the foloowing for\n";
> printf "the first record: <$c>\n";
> die "Correct and rerun";
> }
> $b =~ s/B //;
> $c =~ s/C //;
>
> if ($b eq $c) {
> print "B $b\n";
> }
> elsif ($b ne $c) {
> print "B $b\n";
> print "C $c\n";
> }
>
> }
> __DATA__
> B water
> C water
>
> OUTPUT:
> B water
>
>
> Wags ;)
> -----Original Message-----
> From: M z [mailto:[EMAIL PROTECTED]]
> Sent: Monday, March 04, 2002 12:19
> To: [EMAIL PROTECTED]
> Subject: urgent redundancy question
>
>
> 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.
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Sports - sign up for Fantasy Baseball
> http://sports.yahoo.com
>
> --
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
[EMAIL PROTECTED]
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - sign up for Fantasy Baseball
http://sports.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]