Removing data on a condition

Following is the code:

! /usr/local/bin/perl -w

###prompt for input####
print "Input path and file name:\n";
($a=<STDIN>);

###If cannot open provide error output####
open(IN,$a) || die "Cannot open file $a:$!";

###ensure there is a new line character placed at the end of every ###
###line read in has a \n character at the end###
$/="\n";

####open file for output####
open(OUT,">/free/tmclaugh/perl/DEF_FILE/ztl(volume).def") || die "Cannot open file>:!";

####print header in output file#####
print(OUT "INITIALIZATION\n");
print(OUT "BIN_SIZE 200 200\n");
print(OUT "PT_OF_ORIGIN\t171500\t0852800\n");
print(OUT "PT_OF_TANGENCY\t254236\t0765204\n");
print(OUT "E_radius\t3433.138\n");      
print(OUT "DATA_SOURCE <track data>\n");
print(OUT "DATA_DESTINATION <path to output>\n");
print(OUT "TIME_DIFFERENCE ####\n");
print(OUT "INPUT_FILE_FORMAT o\n");
print(OUT "INPUT_FILE_DATE mm/dd/yy\n");
print(OUT "END\n");
print(OUT "#This file is used with resource monitor version 3.0 and 4.0\n");

$prev_begin='';
$prev_data='';
while(<IN>){
      chomp;
        @fields = split(/:/); #array to hold parsed query split by :
        $begin= "BEGIN_RESOURCE\n".
        "TYPE\tVOLUME\n".
        "NAME\tZTL$fields[0]$fields[1]\n";
               
        $data = "DATA $fields[4] $fields[5]\n#\n#\n";

        #if the alt_start and alt_end do not equal the alt_start and
        #the alt_end from the previous loop then print
        #DATA lat lng
        print OUT $prev_data if $prev_data ne $data || $prev_begin ne $begin;
        $prev_data = $data;
               
        #if sector_info and module do not equal the join of the
        #sector_info and module from the previous loop
        #then print:
        #BEGIN_RESOURCE
        #TYPE VOLUME
        #NAME ZMA(MIAMI), sector_info, and module
        print OUT $begin if $begin ne $prev_begin;
        $prev_begin=$begin;

        #print the LOCATION lat lng
        print(OUT "LOCATION $fields[2] $fields[3]\n");
        }
       print OUT $prev_data;
close(IN);
print (OUT "END");
close(OUT);

I would like it not to print out $data = "DATA $fields[4] $fields[5]\n#\n#\n"; is equal to DATA 998 999

Any help would be much appreciated
tomatocansAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tomatocansAuthor Commented:
Adjusted points to 25
0
tomatocansAuthor Commented:
Hey Guys,

Tried to increase point by purchasing them. Would not work. I will make the questions worth more poins once I can purchase them

Thanks
0
tomatocansAuthor Commented:
Here is updated code and I can't understand why it does not work:

#! /usr/local/bin/perl -w

###prompt for input####
print "Input path and file name:\n";
($a=<STDIN>);

###If cannot open provide error output####
open(IN,$a) || die "Cannot open file $a:$!";

###ensure there is a new line character placed at the end of every ###
###line read in has a \n character at the end###
$/="\n";

####open file for output####
open(OUT,">/free/tmclaugh/ztl/VOLUME_DEF_FILE/ztl_volumexxa.def") || die "Cannot open file>:!";

####print header in output file#####
print(OUT "INITIALIZATION\n");
print(OUT "BIN_SIZE 200 200\n");
print(OUT "PT_OF_ORIGIN\t171500\t0852800\n");
print(OUT "PT_OF_TANGENCY\t254236\t0765204\n");
print(OUT "E_radius\t3433.138\n");      
print(OUT "DATA_SOURCE <track data>\n");
print(OUT "DATA_DESTINATION <path to output>\n");
print(OUT "TIME_DIFFERENCE ####\n");
print(OUT "INPUT_FILE_FORMAT o\n");
print(OUT "INPUT_FILE_DATE mm/dd/yy\n");
print(OUT "END\n");
print(OUT "#This file is used with resource monitor version 3.0 and 4.0\n");

$prev_begin='';
$prev_data='';
$dummy_data="DATA 998 998\n#\n#\n";
while(<IN>){
      chomp;
        @fields = split(/:/); #array to hold parsed query split by :
        $fields[6]=($fields[1]+1);
        $begin= "BEGIN_RESOURCE\n".
        "TYPE\tVOLUME\n".
        "NAME\tZTL$fields[0]M$fields[6]\n";        
        $data = "DATA $fields[4] $fields[5]\n#\n#\n";
        #if the alt_start and alt_end do not equal the alt_start and
        #the alt_end from the previous loop then print
        #DATA lat lng
        print OUT $prev_data if $prev_data ne $data || $prev_begin ne $begin;
        $prev_data = $data;
               
        #if sector_info and module do not equal the join of the
        #sector_info and module from the previous loop
        #then print:
        #BEGIN_RESOURCE
        #TYPE VOLUME
        #NAME ZMA(MIAMI), sector_info, and module
        print OUT $begin if $begin ne $prev_begin && $data ne dummy_data;
        $prev_begin=$begin;

        #print the LOCATION lat lng
        print(OUT "LOCATION $fields[2] $fields[3]\n");
        }
       print OUT $prev_data && $data ne $dummy_data;

close(IN);
print (OUT "END");
close(OUT);

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

adam923Commented:
where and how does this program fail?
is it not compiling or just not giving you the desired answer?
0
tomatocansAuthor Commented:
Continues to print out even when $fileds[4] and $fields[5] = 998 999 which prints out DATA 998 999
0
tomatocansAuthor Commented:
Only want it to print out when $fields[4] and $fields[5] are not equal to 998 and 999.
0
adam923Commented:
i'd recommending adding some parenthesis to your statements that are both print and conditional.. or make them traditional conditionals... if ( condition ) { BLOCK} instead, it will be clearer this way as to what the precedence is... also, when using logic operators with conditionals you need to repeat the conditional for each side of the logic operator for example:
WRONG: if ( $a eq "hello" || "hi" ) {BLOCK}
RIGHT: if ( $a eq "hello" || $a eq "hi" ) {BLOCK}
0
tomatocansAuthor Commented:
So
print OUT $begin if $begin ne $prev_begin && $data ne dummy_data;

should be

if ($begin ne $ prev_begin || $data ne $dummy data){
  print OUT $begin;
  }

AND

print OUT $prev_data && $data ne $dummy_data;

should be

if($data ne $dummy_data){
   print OUT $prev_data;
 }

Correct?
   
0
adam923Commented:
those print statements won't work because print is a "greedy" list operator... it considers everything after it to be part of the list that it should print, so your new versions should work but
why did the && change to || in the first example?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tomatocansAuthor Commented:
Tired mistake. Thanks I try it first think tomorrow morning should work
0
ozoCommented:
I don't think there's anything wrong with
print if condition
but
 $data ne dummy_data
should probably be
 $data ne $dummy_data


print OUT $prev_data && $data ne $dummy_data;
is confusing.  I don't think you meant to print a true or false condition.
0
tomatocansAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.