[Cedarvalley] storing a hash in a list...

Aaron Thompson thompson at cns.uni.edu
Tue Nov 18 09:48:21 CST 2003


Thanks Steve,

 I was just going to post a solution I came up with when I read
 this message... 

 ...
 my $count = 0;
 for $url (@rss){
   ... building %rss_data
   %{$web_data[$count]} = %rss_data;
   $count++
 }#rof
 ...

 Thanks for the idea - I tried it and it works well.
 
 I like your solution better ;) I'm going to re-write my loop and
 get rid of the iterator.

 @

On Mon, Nov 17, 2003 at 06:32:46PM -0600, Stephen D. Wells wrote:
> My cedarnet email was down and I don't know if a response has been
> generated yet however this is a detailed account of what is happening
> and how to avoid it:
> 
> using @list = \%hashed_data stores a pointer to that data.  Meaning that
> it's not a copy but a link.  What you need is exactly what you said... a
> copy to a reference.  The reason is that each time you go through the
> list you are pointing to the same data...
> 
> Try this instead:
> 
> push(@list, {%hashed_data});
> 
> STEVE
> 
> On Thu, 2003-11-13 at 23:42, Aaron Thompson wrote:
> > I am building a hash as I loop thru some data.. and would like to
> > store that hash in another list for later use. I'm having trouble
> > getting the hash to store properly. Any one know how to return a
> > reference to a copy of a hash?
> > 
> > I started with:
> >   @list = \%hashed_data 
> > 
> > but found that I got lots of references to the same data
> > I tried:
> > 
> >   @list = \%{%hashed_data} 
> >   
> > This had the sam results.
> > 
> > Thanks,
> > 
> >   @
> -- 
> Stephen D. Wells <wells at cedarnet.org>

-- 
Aaron Thompson   Unix Systems Administrator, College of Natural Science
University of Northern Iowa                      Cedar Falls, IA  50614

"It is not the fall that kills you. It's the sudden stop at the end."
                                                        -Douglas Adams



More information about the Cedarvalley mailing list