0

My question is shown in the title.

I have raw data which may have various elements. I want to define hash whose name is based on the raw elements. Here is an example.

my $line="SI AL";
my @values=split(/\s+/,$line);chomp(@values);

I want to use the element values, like "SI" and "AL", to define hashes, like %hash_SI_CN_tot_amt, %hash_AL_CN_tot_amt, where "SI" and "AL" should be a variable. How can I define hash using variable values? Any further suggestion would be highly appreciated.

Leon
  • 444
  • 2
  • 15

1 Answers1

1

Further suggestion: don't do this.

Use a multi-dimensional hash instead.

@values = ("SI","AL");
...
$hash_CN_tot_amt{"SI"}{$key} = $value;
$hash_CN_tot_amt{$values[1]}{$key2} = $value2;
mob
  • 117,087
  • 18
  • 149
  • 283