We help IT Professionals succeed at work.

Storing data into a hash from file

saibsk
saibsk asked
on
I have a file which has this format each word dot separated:
SubAcctDtls.Id.IdAndPurp
SubAcctDtls.Id.IdAndPurp.Id
SubAcctDtls.Id.IdAndPurp.Id.Prtry
SubAcctDtls.Id.IdAndPurp.Id.Prtry.Id

I want to store each word in a hash. And I dont want store any duplicates in the hash i.e I want to store SubAcctDtls,Id,IdAndPurp,Prtry in the hash. Please advise.
Comment
Watch Question

ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
Hashes don't store duplicate keys

Author

Commented:
how should i store the data in the hash while reading from the hash?
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
What do you mean when you say store the data in the hash while reading from the hash?
How are you doing it now,
what does it produce, and what do you want it to produce?

Author

Commented:
Sorry How do i store the data in the hash while reading from the file. I want to store in the hash something like this
SubAcctDtls
Id
IdAndPurp
Prtry
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015
Commented:
while( <> ){
   s/\s+$//;
   @hash{split/\./} =();
}
print "$_\n" for keys %hash;

Explore More ContentExplore courses, solutions, and other research materials related to this topic.