Mailing List Archive

array of hash references question
hi all

I don't think i totally understand hash references

I've made an array of linked stories, @linked_articles, and now I
want to split this list into two other arrays, one with stories that
have a 'print_only' checkbox checked, and the remainder into
@online_articles.

The problem is my new arrays are full of the actual story content -
not references to the original story which is what @linked_articles
contains. How did I loose my hash references? Should I use push in
this context or do I need to use map? Or am I just not passing my $_
variable incorrectly?

@linked_articles = map {$_->get_related_story } $story-
>get_elements('linked_article');
foreach (@linked_articles){
my ($po) = $_->get_elements('print_only');
if ($po && $po->get_value('1')){
push (@print_only_articles , %{$_}); # i previously tried
using just $_ to push onto the array
}else{
push (@online_articles , %{$_});
}
}

thanks very much,
Dawn
Re: array of hash references question - nevermind [ In reply to ]
HI all

My code wasn't working because I didn't test for an undefined value -
it had nothing to do with the hash reference. So this should be correct:

@linked_articles = map {$_->get_related_story } $story-
>get_elements('linked_article');
foreach (@linked_articles){
my ($po) = $_->get_elements('print_only');
if ($po && $po->get_value('1')){
push (@print_only_articles , $_);
}else{
push (@online_articles , $_);
}
}

Dawn


On 5-Sep-10, at 9:04 PM, Dawn Buie wrote:

> hi all
>
> I don't think i totally understand hash references
>
> I've made an array of linked stories, @linked_articles, and now I
> want to split this list into two other arrays, one with stories that
> have a 'print_only' checkbox checked, and the remainder into
> @online_articles.
>
> The problem is my new arrays are full of the actual story content -
> not references to the original story which is what @linked_articles
> contains. How did I loose my hash references? Should I use push in
> this context or do I need to use map? Or am I just not passing my $_
> variable incorrectly?
>
> @linked_articles = map {$_->get_related_story } $story-
> >get_elements('linked_article');
> foreach (@linked_articles){
> my ($po) = $_->get_elements('print_only');
> if ($po && $po->get_value('1')){
> push (@print_only_articles , %{$_}); # i previously tried
> using just $_ to push onto the array
> }else{
> push (@online_articles , %{$_});
> }
> }
>
> thanks very much,
> Dawn