Solution here.... I would like to thank Thilo for all his help on this.
my $enumref;
sub enum {
my ( $fieldid, $valref, $schema ) = @_;
# -- Load status field into hash reference with values as keys, integers
as values
my $fieldinfo = ars_GetField($c, $schema, $fieldid) or error_cleanup(
"ERROR: Cannot get field information for $schema: $ars_errstr" );
my @enumvals =
@{$fieldinfo->{"limit"}->{"enumLimits"}->{"regularList"}};
my $counter = 0;
foreach (@enumvals) {
$valref->{$schema}->{$fieldid}->{$_} = $counter;
$counter++;
}
return $valref;
}
# -- This subroutine is basically the opposite of above to work with
values already in enum my $enameref; sub ename {
my ( $fieldid, $nameref, $schema ) = @_;
# -- Load status field into hash reference with integers as keys, text
values as values
my $fieldinfo = ars_GetField($c, $schema, $fieldid) or error_cleanup(
"ERROR: Cannot get field information: $ars_errstr" );
my @enamevals =
@{$fieldinfo->{"limit"}->{"enumLimits"}->{"regularList"}};
my $counter = 0;
foreach (@enamevals) {
$nameref->{$schema}->{$fieldid}->{$counter} = $_;
$counter++;
}
return $nameref;
}
my @SIMFieldnum = qw(7 536871022 536870948 536871022 536870997 536871002
536871008 536870969 536870993 536871009 536871012 536871013 536871014
536871015); # Loop thru and build datastructure to reference select
fields foreach (@SIMFieldnum) {
$enumref = enum($_, $enumref, $schema);
$enameref = ename($_, $enameref, $schema); }
$enumref->{$schema}->{'7'}->{$row[0]} # Find enum value from string
value for array ref 0
************************************************************************
**
Just create a hash from @enumValues:
my %enumValueHash = ();
for( $i = 0; $i < $#enumValues; ++$i ){
$enumValueHash{$enumValues[$i]} = $i; }
or, slightly more compact:
my %enumValueHash = map {$enumValues[$_] => $_} (0..$#enumValues);
You could then put all those values into one large hash structure, like
my %ENUM_VALUES;
foreach my $fieldId ( @fields ){
....
my @enumValues = ...
for( $i = 0; $i < $#enumValues; ++$i ){
$ENUM_VALUES{$fieldId}{$enumValues[$i]} = $i;
}
}
and look the values up later as:
$numericEnumValue = $ENUM_VALUES{$fieldID}{$charEnumValue}:
Regards,
Thilo Stapff
Lipford, Willy wrote:
> Sorry to bother you again, I now see how to use the hash contents of
> limit->enum , etc...
>
> I am trying to write a function that takes the string value that is
> submitted in my import file and convert to the integer is required.
>
> For instance: Field(Carrier) - Submitted values is "Cingluar" which is
> numeric 2 for import.
>
> But in the enumLimit hash there is no coordinated integer value, all I
> have is the array slice value from when I grab them all, like
> @enumValues[0] would be the 1st string in that menu...
>
> Any hints or direction you can give me? I have over 40 selection
> fields on this form and do not want to hardcode these values and would
> like to "lookup" on the fly.
>
> Once I get this resolved I will post on all the lists giving you
> credit, I really appreciate it. My perl skills are getting dull with
> all the PHP and Remedy development I have been doing.
>
> Cheers,
> Will Lipford
>
>
> -----Original Message-----
> From: Thilo Stapff [mailto:[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> ]
> Sent: Friday, October 12, 2007 7:45 AM
> To: Lipford, Willy
> Subject: Re: Selection Field import Problem Options
>
> Basically it's a shortcut for:
>
> my %enumValues = ();
> foreach( @{$fieldStruct->{limit}{enumLimits}{customList}} ){
> $enumValues{$_->{itemName}} = $_->{itemNumber}; }
>
> Run "perldoc -f map" for more information.
> If you want to print out the values, just insert a line like
>
> print "$_->{itemName} => $_->{itemNumber}\n";
>
> into the loop.
>
> Of course this example only applies to selection fields with custom
> selection values.
>
>
> Regards,
> Thilo Stapff
>
>
> Lipford, Willy wrote:
>> Thanks for the information, I haven't used the map function all that
>> much, is that just loading a hash or arrays? How would I print that
> out?
>>
>> Regards,
>> Will Lipford
>>
>>
>>
>> You might use ars_GetField() to retrieve the internal field structure
>> description, e.g. like this:
>>
>> my $fieldStruct = ars_GetField( $ctrl, $formName, $fieldId ); my
>> @enumValues = @{$fieldStruct->{limit}{enumLimits}{regularList}};
>>
>> or for custom selection fields:
>>
>> my %enumValues = map {$_->{itemName} => $_->{itemNumber}}
>> @{$fieldStruct->{limit}{enumLimits}{customList}};
>>
>> Regards,
>> Thilo Stapff
This e-mail message is for the sole use of the intended recipient(s) and may
contain confidential and privileged information of Transaction Network
Services. Any unauthorized review, use, disclosure or distribution is
prohibited. If you are not the intended recipient, please contact the sender
by reply e-mail and destroy all copies of the original message.
_______________________________________________________________________________
UNSUBSCRIBE or access ARSlist Archives at www.arslist.org ARSlist:"Where the
Answers Are"