tomatocans
asked on
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_F ILE/ztl(vo lume).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\t085 2800\n");
print(OUT "PT_OF_TANGENCY\t254236\t0 765204\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]$field s[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
! /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/
####print header in output file#####
print(OUT "INITIALIZATION\n");
print(OUT "BIN_SIZE 200 200\n");
print(OUT "PT_OF_ORIGIN\t171500\t085
print(OUT "PT_OF_TANGENCY\t254236\t0
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]$field
$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
ASKER
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
Tried to increase point by purchasing them. Would not work. I will make the questions worth more poins once I can purchase them
Thanks
ASKER
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_volume xxa.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\t085 2800\n");
print(OUT "PT_OF_TANGENCY\t254236\t0 765204\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$fiel ds[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);
#! /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/
####print header in output file#####
print(OUT "INITIALIZATION\n");
print(OUT "BIN_SIZE 200 200\n");
print(OUT "PT_OF_ORIGIN\t171500\t085
print(OUT "PT_OF_TANGENCY\t254236\t0
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$fiel
$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);
where and how does this program fail?
is it not compiling or just not giving you the desired answer?
is it not compiling or just not giving you the desired answer?
ASKER
Continues to print out even when $fileds[4] and $fields[5] = 998 999 which prints out DATA 998 999
ASKER
Only want it to print out when $fields[4] and $fields[5] are not equal to 998 and 999.
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}
WRONG: if ( $a eq "hello" || "hi" ) {BLOCK}
RIGHT: if ( $a eq "hello" || $a eq "hi" ) {BLOCK}
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tired mistake. Thanks I try it first think tomorrow morning should work
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.
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.
ASKER
Thanks
ASKER