For some reason, this code will not work. There are no unmatched quotes. Plus, if I intentionally make an error by placing a bare word or symbol anywhere in my code, this single error shows up:
Can't find string terminator ' " ' anywhere before EOF at ...
In this code, I am creating a new file.
1. I open a text file with three columns from $ARGV[0].
2. I create three hashes from this file.
3. I close this text file (optional?).
4. Then, I open an outgoing file.
5. I open the same text file with three columns from $ARGV[1].
6. I print stuff into the outgoing file.
7. I close the outgoing file and the text file.
#! /usr/bin/perl - w
$infile1 = $ARGV[0]; #
open ( INA, $infile1 );
while ($line = <INA>) {
@array = split " ", $line;
$x = $array[1];
$y = $array[2];
$temp = sprintf "%.1f_%.1f", $x, $y;
$temp2 = sprintf "%.1f_%.1f", $y, $x;
$coordinate_counter{$temp}++;
$coordinate_counter2{$temp2}++;
}
foreach $position (keys %coordinate_counter) {
if ($coordinate_counter{$position} < 10,000) {
$height{$position} = 1;
} elsif (($coordinate_counter{$position} >= 10,000) && ($coordinate_counter{$position} < 20,000)) {
$height{$position} = 2;
} elsif (($coordinate_counter{$position} >= 20,000) && ($coordinate_counter{$position} < 30,000)) {
$height{$position} = 3;
} elsif (($coordinate_counter{$position} >= 30,000) && ($coordinate_counter{$position} < 40,000)) {
$height{$position} = 4;
} elsif (($coordinate_counter{$position} >= 40,000) && ($coordinate_counter{$position} < 50,000)) {
$height{$position} = 5;
} elsif ($coordinate_counter{$position} > 50,000) {
$height{$position} = 6;
}
}
foreach $position2 (keys %coordinate_counter2) {
if ($coordinate_counter2{$position2} < 10,000) {\
$height2{$position2} = 1;
} elsif (($coordinate_counter2{$position2} >= 10,000) && ($coordinate_counter2{$position2} < 20,000)) {
$height2{$position2} = 2;
} elsif (($coordinate_counter2{$position2} >= 20,000) && ($coordinate_counter2{$position2} < 30,000)) {
$height2{$position2} = 3;
} elsif (($coordinate_counter2{$position2} >= 30,000) && ($coordinate_counter2{$position2} < 40,000)) {
$height2{$position2} = 4;
} elsif (($coordinate_counter2{$position2} >= 40,000) && ($coordinate_counter2{$position2} < 50,000)) {
$height2{$position2} = 5;
} elsif ($coordinate_counter2{$position2} > 50,000) {
$height2{$position2} = 6;
}
}
open(OUTGOING, ">wtro_vs_wvo_3d.txt" );
$infile2 = $ARGV[1];
open ( INB, $infile2 );
while ($line = <INB>) {
@array = split " ", $line;
$x = $array[1];
$y = $array[2];
$temp = sprintf "%.1f_%.1f", $x, $y;
$temp2 = sprintf "%.1f_%.1f", $y, $x;
print OUTGOING "$line $height{$temp} $height2{$temp2};
}
close( OUTGOING );
Can't find string terminator ' " ' anywhere before EOF at ...
In this code, I am creating a new file.
1. I open a text file with three columns from $ARGV[0].
2. I create three hashes from this file.
3. I close this text file (optional?).
4. Then, I open an outgoing file.
5. I open the same text file with three columns from $ARGV[1].
6. I print stuff into the outgoing file.
7. I close the outgoing file and the text file.
#! /usr/bin/perl - w
$infile1 = $ARGV[0]; #
open ( INA, $infile1 );
while ($line = <INA>) {
@array = split " ", $line;
$x = $array[1];
$y = $array[2];
$temp = sprintf "%.1f_%.1f", $x, $y;
$temp2 = sprintf "%.1f_%.1f", $y, $x;
$coordinate_counter{$temp}++;
$coordinate_counter2{$temp2}++;
}
foreach $position (keys %coordinate_counter) {
if ($coordinate_counter{$position} < 10,000) {
$height{$position} = 1;
} elsif (($coordinate_counter{$position} >= 10,000) && ($coordinate_counter{$position} < 20,000)) {
$height{$position} = 2;
} elsif (($coordinate_counter{$position} >= 20,000) && ($coordinate_counter{$position} < 30,000)) {
$height{$position} = 3;
} elsif (($coordinate_counter{$position} >= 30,000) && ($coordinate_counter{$position} < 40,000)) {
$height{$position} = 4;
} elsif (($coordinate_counter{$position} >= 40,000) && ($coordinate_counter{$position} < 50,000)) {
$height{$position} = 5;
} elsif ($coordinate_counter{$position} > 50,000) {
$height{$position} = 6;
}
}
foreach $position2 (keys %coordinate_counter2) {
if ($coordinate_counter2{$position2} < 10,000) {\
$height2{$position2} = 1;
} elsif (($coordinate_counter2{$position2} >= 10,000) && ($coordinate_counter2{$position2} < 20,000)) {
$height2{$position2} = 2;
} elsif (($coordinate_counter2{$position2} >= 20,000) && ($coordinate_counter2{$position2} < 30,000)) {
$height2{$position2} = 3;
} elsif (($coordinate_counter2{$position2} >= 30,000) && ($coordinate_counter2{$position2} < 40,000)) {
$height2{$position2} = 4;
} elsif (($coordinate_counter2{$position2} >= 40,000) && ($coordinate_counter2{$position2} < 50,000)) {
$height2{$position2} = 5;
} elsif ($coordinate_counter2{$position2} > 50,000) {
$height2{$position2} = 6;
}
}
open(OUTGOING, ">wtro_vs_wvo_3d.txt" );
$infile2 = $ARGV[1];
open ( INB, $infile2 );
while ($line = <INB>) {
@array = split " ", $line;
$x = $array[1];
$y = $array[2];
$temp = sprintf "%.1f_%.1f", $x, $y;
$temp2 = sprintf "%.1f_%.1f", $y, $x;
print OUTGOING "$line $height{$temp} $height2{$temp2};
}
close( OUTGOING );