Hello All,

I'm having a time using a hash reference and wanting
to use the reference to create a new list of hashes to do my dirty work - in essence making a copy of the references for the new list of hashes to use.

while (my $ref = $sth->fetchrow_hashref()) { if ($ref->{multiple}) { foreach my $i (1 .. $number_of_members) { my $new_name = "member" . $i . "_" . $ref->{name}; $ref->{name} = $new_name; $ref->{label} = "Member # $i" . " " . $ref->{label}; push @names, $ref; } } else { push @apps, $ref; } } push @names, @apps;
What I want to do is -depending on the # of members- create a list of hashes (in example @names) that does not reference the original $ref's references but makes a copy for its own use. I'm a little confused on how to copy the contents of the reference instead of directly dealing with the reference itself. In the above example the number of members can vary so I want to give each one its own hash in a new list. But what happens is that instead of getting what I want:
member1_first_name ($ref->{name}) Member #1 First Name ($ref->{label}) member2_last_name Member #2 Last Name ...up to # of members
I get:
member2_member1_first_name Member #2 Member #1 First Name member2_member1_first_name Member #2 Member #1 First Name member2_member1_last_name Member #2 Member #1 Last Name member2_member1_last_name Member #2 Member #1 Last Name
Any suggestions?

update (broquaint): added <code> tags


In reply to Making a new list of hashes from a hashref by dogen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.