G
G
I’m looping through a sales_file looking for matches. The file
has a number of entries such as the following:
sales item aaa | m423a
sales item bbb | m423
sales item ccc | m423b
sales item ddd | 423
These refer to sales_item and code respectively.
Here is the code segment:
open FILE, "<$sales_file";
while (<FILE>) {
($sales_item, $code) = split /\|/;
if (index($code, $entered_code) != -1) {
$list .= "<br>" if ($list);
$list .= $sales_item;
}
} # while
close FILE;
The problem is, if the $entered_code is 423 I get matches for all 4
when I would only want matches for the fourth sales item “sales
item ddd” line. Similarly, an $entered_code of m423 would match
the first 3. Any suggestions on how I can get the right matches,
keeping in mind that I would prefer to do it in code, and not alter
the sales_file.
Thanks,
C
has a number of entries such as the following:
sales item aaa | m423a
sales item bbb | m423
sales item ccc | m423b
sales item ddd | 423
These refer to sales_item and code respectively.
Here is the code segment:
open FILE, "<$sales_file";
while (<FILE>) {
($sales_item, $code) = split /\|/;
if (index($code, $entered_code) != -1) {
$list .= "<br>" if ($list);
$list .= $sales_item;
}
} # while
close FILE;
The problem is, if the $entered_code is 423 I get matches for all 4
when I would only want matches for the fourth sales item “sales
item ddd” line. Similarly, an $entered_code of m423 would match
the first 3. Any suggestions on how I can get the right matches,
keeping in mind that I would prefer to do it in code, and not alter
the sales_file.
Thanks,
C