J
Jay
I'm trying to write a quick program that outputs a table of compatable
parts for our company. The table is stored in a CSV file. The part I'm
having trouble with is an if statement that seems to be letting things
through when they shouldn't match.
Here is the source code up to the part that isn't working. (It used to
be a little cleaner, but by the end of yesterday I was coding by
flailing around a little).
$compatFileName = "compats.csv";
open(COMPATFILE, $compatFileName) or die "Can't open compatibility
file: $!\n";
#NEED A VARIABLE CALLED $whatProducts that is a comma deliminated list
of products for this page
###################################
##For Debugging
$whatProducts = '104-AI12-8';
#################################
@products = split /,/, $whatProducts;
$compatLine = <COMPATFILE>;
@partNames = split /,/, $compatLine;
foreach $currentProduct (@products)
{
while ($compatLine = <COMPATFILE>)
{
@currentCompat = split /,/, $compatLine;
$count = 0;
$compareTo = join "", split "-", @currentCompat[0];
$currentProduct = join "", split "-", $currentProduct;
chomp ($compareTo);
if ( $currentProduct == $compareTo)
{
print "Checking for: ";
print $compareTo;
print "\tCurrent Product:";
print $currentProduct;
print "\n";
The if statement at the end seems to be letting through anything where
the first three characters match. Here is a few lines from the output:
Checking for: 104AI128 Current Product:104AI128
Checking for: 104AIM32 Current Product:104AI128
Checking for: 104AIM32A Current Product:104AI128
Checking for: 104AIO128 Current Product:104AI128
Checking for: 104AIO1616E Current Product:104AI128
Checking for: 104AIO1616W Current Product:104AI128
Checking for: 104AO124 Current Product:104AI128
I haven't written anything in PERL in a long time, and I was never an
expert at it. If there is a beginner newsgroup I should be posting this
kind of question to please let me know and I'll apologize in advance
for putting this in the wrong place.
-- Jay
parts for our company. The table is stored in a CSV file. The part I'm
having trouble with is an if statement that seems to be letting things
through when they shouldn't match.
Here is the source code up to the part that isn't working. (It used to
be a little cleaner, but by the end of yesterday I was coding by
flailing around a little).
$compatFileName = "compats.csv";
open(COMPATFILE, $compatFileName) or die "Can't open compatibility
file: $!\n";
#NEED A VARIABLE CALLED $whatProducts that is a comma deliminated list
of products for this page
###################################
##For Debugging
$whatProducts = '104-AI12-8';
#################################
@products = split /,/, $whatProducts;
$compatLine = <COMPATFILE>;
@partNames = split /,/, $compatLine;
foreach $currentProduct (@products)
{
while ($compatLine = <COMPATFILE>)
{
@currentCompat = split /,/, $compatLine;
$count = 0;
$compareTo = join "", split "-", @currentCompat[0];
$currentProduct = join "", split "-", $currentProduct;
chomp ($compareTo);
if ( $currentProduct == $compareTo)
{
print "Checking for: ";
print $compareTo;
print "\tCurrent Product:";
print $currentProduct;
print "\n";
The if statement at the end seems to be letting through anything where
the first three characters match. Here is a few lines from the output:
Checking for: 104AI128 Current Product:104AI128
Checking for: 104AIM32 Current Product:104AI128
Checking for: 104AIM32A Current Product:104AI128
Checking for: 104AIO128 Current Product:104AI128
Checking for: 104AIO1616E Current Product:104AI128
Checking for: 104AIO1616W Current Product:104AI128
Checking for: 104AO124 Current Product:104AI128
I haven't written anything in PERL in a long time, and I was never an
expert at it. If there is a beginner newsgroup I should be posting this
kind of question to please let me know and I'll apologize in advance
for putting this in the wrong place.
-- Jay