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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

better way to create array of hashes 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I have a Comma Separated Value , constant, I wish to create and array of each value which is a hash value pair.

I'm currently using the following code and it works fine, I just get a feeling there is a better way :)
Code:
my @reg_type = split(/,/,REG_TYPE);
for(@reg_type){
    $_ = {'Regulation' => $_};
}

cheers, 1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
hmm I thought I could incorporate the split into it also, from what I understand the 'map' command internally just does a for loop anyhow, so not sure it's saving any overhead :-(



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
map" in a void context? Yeuch!!

How about:
Code:
my @reg_type = map +{Regulation => $_}, split(/,/,REG_TYPE);
?
 
now that's what i'm talking about isnid, you da man!

:)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top