Hello Jeroen.
Jeroen Lodewijks wrote:
>
> I have a question. I have a sub which build a hash of list values.
> I want to put those list values directly into some local variables
> but I am unable to get the syntax right.
>
> I have something like this at the moment:
>
> sub FillHash
> {
> my($db) = @_;
> my (%formatrules);
> my $lcsr;
> my @values;
>
> $lcsr = $db->prepare(<<'') || ataerr::dbprepare($db);
> SELECT index1_value, index2_value, result1_value, result2_value
> FROM derived_attribute_array
> WHERE derived_attribute_id = (SELECT derived_attribute_id
> FROM derived_attribute_history
> WHERE derived_attribute_name = ?
> AND SYSDATE BETWEEN
> effective_start_date AND effective_end_date)
>
> if ($lcsr->execute($DA_TABLE)) {
> while (@values = $lcsr->fetchrow) {
> $formatrules{$values[0], $values[1]} = [EMAIL PROTECTED];
> }
> }
> $lcsr->finish;
>
> return %formatrules;
> }
>
>
> my (%formatrules) = FillHashFromDerived;
>
>
> $billing_output_format = $formatrules{$invoice_format_id,
> $mandant_id}[0]; $mandant = $formatrules{$invoice_format_id,
> $mandant_id}[1]; $destination_key = $formatrules{$invoice_format_id,
> $mandant_id}[2]; $split_key = $formatrules{$invoice_format_id,
> $mandant_id}[3];
>
> This works but I want to replace the last bit with something like:
> ($billing_output_format, $mandant, $destination_key, $split_key) =
> @formatrules{$invoice_format_id, $mandant_id};
>
> Everytime I try something like this it errors or returns nothing.
>
> What is the correct syntax?
You need to dereference the array reference:
$formatrules{$invoice_format_id, $mandant_id}
like this:
@{$formatrules{$invoice_format_id, $mandant_id}}
or, more neatly:
my $data = $formatrules{$invoice_format_id, $mandant_id};
($billing_output_format, $mandant, $destination_key, $split_key) =
@$data;
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]