Question could also be asked, how to compare data between two arrays and perform an action (print cmd) everytime there is a match?
The problem I'm having with the code below is that the comparison in the conditional IF statement is only happening against the first value --$link-- in the array --@route--
I want the comparison between the two arrays to repeat for every value in the first array @route.
Appreciate any guidance or ideas you may be able to lend to get me on track.
Regards,
Hutch
P.S - not sure if the following is relevant... but here is a bit more context in case it helps guide your reply. The first Array --@route-- will contain 3 to 10 values every time the script is run. These values will most always be different from one time to the next.
Whereas the data in the CSV file that is being looped through, will most always not change and will contain 100 to 1000 fairly short lines of data.
[CODE=perl]
# open CSV file to Read From
open(CSV_FILE, "/netmap/sites/list.csv") ||
die "Can't open file: $!";
# turn each value in this array into a single object for purposes of matching against data in the CSV_FILE
# **ARRAY 1**
for $link (@route){
# Open the while loop to read csv file
while (<CSV_FILE>) {
# Delete the new line char for each line
chomp;
# Split each field in the CSV File into an array
# **ARRAY 2**
my @fields = split(/,/);
# conditional statement to print a string of data everytime the while loop sees a match between values in the two arrays
if ($link eq "$fields[3]"){
print "test\n";
print "we have a match for $fields[3]\n";
}
}
}
[/CODE]
The problem I'm having with the code below is that the comparison in the conditional IF statement is only happening against the first value --$link-- in the array --@route--
I want the comparison between the two arrays to repeat for every value in the first array @route.
Appreciate any guidance or ideas you may be able to lend to get me on track.
Regards,
Hutch
P.S - not sure if the following is relevant... but here is a bit more context in case it helps guide your reply. The first Array --@route-- will contain 3 to 10 values every time the script is run. These values will most always be different from one time to the next.
Whereas the data in the CSV file that is being looped through, will most always not change and will contain 100 to 1000 fairly short lines of data.
[CODE=perl]
# open CSV file to Read From
open(CSV_FILE, "/netmap/sites/list.csv") ||
die "Can't open file: $!";
# turn each value in this array into a single object for purposes of matching against data in the CSV_FILE
# **ARRAY 1**
for $link (@route){
# Open the while loop to read csv file
while (<CSV_FILE>) {
# Delete the new line char for each line
chomp;
# Split each field in the CSV File into an array
# **ARRAY 2**
my @fields = split(/,/);
# conditional statement to print a string of data everytime the while loop sees a match between values in the two arrays
if ($link eq "$fields[3]"){
print "test\n";
print "we have a match for $fields[3]\n";
}
}
}
[/CODE]
Comment