Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading a hash with an array 1

Status
Not open for further replies.

Tve

Programmer
May 22, 2000
166
FR
Hi,

I'm trying to load a hash with a array as follows:
Standard syntax would look like this

my @array = (15,89,23);

my %hash = ("Value1" => $array[0],
"Value2" => $array[1],
"Value3" => $array[2]
);

I'm trying to do the assignment in one line. The following code DOES NOT work, but gives an idea of what I want:

my @array = (15,89,23);
my %hash("Value1","Value2","Value3") = @array;


Any suggestions?
AD AUGUSTA PER ANGUSTA

Thierry
 
[tt] my @array = (15,89,23);
my %hash;
@hash{("Value1","Value2","Value3")} = @array;
[/tt]works, as does
[tt] my @array = (15,89,23);
my %hash;
@hash{qw{ Value1 Value2 Value3 }} = @array;
[/tt]but
[tt] my @array = (15,89,23);
my @hash{qw{ Value1 Value2 Value3 }} = @array;
[/tt]fails.
"As soon as we started programming, we found to our surprise that it wasn't as
easy to get programs right as we had thought. Debugging had to be discovered.
I can remember the exact instant when I realized that a large part of my life
from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top