Thanks Franco,
In some cases (with fields other than the state abbreviations we have been discussing here) an exact length will be required, i.e., where NYC and NYCVB are unique values and a precise match is required.
NYCCVB could, for instance, match NYC, however, NYCVB, as a unique value...
To answer part of my own question, substr length can be a variable, so doing an the on-the-fly length change, just before the lookup, is where I will focus my energies, and hopefully get the result I need.
My apologies for the confusion; I am asking two separate, but similar questions in the same thread, and not taking into account that some of the "wildcard" functionality I want will occur by default. Thank you Kevin for your good help to this point. Franco, your understanding of the state...
Some further clarification:
Say I have a lookup field that contains:
"The Box is Blue" ($abbrev)
I would want to match it exactly, but I know some comparison data ($data[8]) will contain:
"The Box is Blue and Large"
Therefore, I would want $abbrev to be "$abbrev.*" (The Box is Blue.*) so if...
What I mean is, what if the field length is variable, i.e. the full state name field, where each text string would be a different length,and the ($abbrev,0,2) would not apply? Is there a wildcard that could be used in such situations?
Here is my previous question from April 9th:
OK, what am I missing here? The abbreviated states lookup are all uppercase, 2-characters, except Arizona, which, for testing purposes I have formatted like this:
AZABBCCDDDGGGEE
The below code works fine for all states, except Arizona which is generating an error...
Is there a means of editing/deleting posts? In my previous post, I have this backwards:
$ab = “$abbrev”;
$ab =~ s/$ab/$ab#WILDCARD CHAR#/;
Since $abbrev is the reference value, what I have there is wrong. The submitted value ( $data[8] ) is what needs to be wildcarded.
I plan to get back to it later today, using something like this (looks OK here, but won't know for sure until I try it):
open(MAP,"<$maplocation")||die "Could not open $maplocation";
while (<MAP>) {
chomp;
($code, $abbrev, $fullname)=split /::/, $_;
$ab = “$abbrev”;
$ab...
By "something else" what do you mean? More than one or two extra characters?
For ewxample, would the code you just submitted apply if the $abbrev field was: "The quick brown fox" and the comparison field was: "The quick brown fox chases cars"?
Exactly what I am thinking, between lines 5 and 6 below.
open(MAP,"<$maplocation")||die "Could not open $maplocation";
while (<MAP>) {
chomp;
($code, $abbrev, $fullname)=split /::/, $_;
$states{$abbrev}=$fullname;
}
close MAP;
Actually, let me clarify that.
If a state abbreviation field had one or more extra characters, i.e. "AZ" was written as AZX in the lookup file, and I wanted make sure it was interpreted as "AZ" using a wildcard, could that work?
I dont see how "^AZ" could be incorporated into this code...
Out of curiosity, would this also work with wildcards?
For example, if I wanted all state abbreviations that began with "A" -- AZ, AL, AK, AR, -- all return "Arizona" as the $data[d8] value.
Would this code accommodate the use of "." or "^" and other wildcard characters?
$data[8] =...
Works perfectly now! Thanks so much for all the good feedback.
I Will eventually need to apply this lookup logic to additional files, but I do not anticipate too many problems. :-)
Appears the 'while' loop is matching the state abbreviation, but not associating it with the full state name, which suggests I need another array and/or 'for' loop within the while, which seems more convoluted than my original code. But if it works, I'll use it. Any thoughts?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.