I don't know why I can't figure this out, seems like it should be simple enough... I create a new struct:

struct archive_e => { name => '$', criteria => '$', regex => '@', file_owner => '$', file_group => '$', vsn => '$' };

I have a loop that reads all of the parameters from a configuration database and creates a new struct for each

$newp = archive_e->new(); $newp->criteria($pdirective); $newp->name($pname); $newp->regex(\@regexes); $newp->file_owner($pfowner); $newp->file_group($pfgroup); $newp->vsn($fqvsn); print Dumper $newp; push(@ap, $newp);<-------Where it goes south? print "ap array starts here\n"; print Dumper @ap;

So first I dump $newp, then I push it into ap, and dump that. And the first iteration looks good:

$VAR1 = bless( { 'archive_e::regex' => [ 'ogg', 'mp3' ], 'archive_e::file_group' => 'ANY', 'archive_e::name' => 'music', 'archive_e::criteria' => 'archive-e', 'archive_e::vsn' => 'root/SteveMusic', 'archive_e::file_owner' => 'ANY' }, 'archive_e' ); ap array starts here $VAR1 = bless( { 'archive_e::regex' => [ 'ogg', 'mp3' ], 'archive_e::file_group' => 'ANY', 'archive_e::name' => 'music', 'archive_e::criteria' => 'archive-e', 'archive_e::vsn' => 'root/SteveMusic', 'archive_e::file_owner' => 'ANY' }, 'archive_e' );

Then the next loop iteration adds the next structure (which looks good again) and does another push of that into the ap array and it all gets corrupted:

$VAR1 = bless( { 'archive_e::regex' => [ 'avc', 'avr', 'mks', 'mkv', 'mov', 'mp4', 'mpeg', 'mpeg1', 'mpeg2', 'mpeg4', 'mpg', 'mpg4' ], 'archive_e::file_group' => 'ANY', 'archive_e::name' => 'Movies', 'archive_e::criteria' => 'archive-e', 'archive_e::vsn' => 'root/Video', 'archive_e::file_owner' => 'ANY' }, 'archive_e' ); ap array starts here $VAR1 = bless( { 'archive_e::regex' => [ 'avc', 'avr', 'mks', 'mkv', 'mov', 'mp4', 'mpeg', 'mpeg1', 'mpeg2', 'mpeg4', 'mpg', 'mpg4' ], 'archive_e::file_group' => 'ANY', 'archive_e::name' => 'music', 'archive_e::criteria' => 'archive-e', 'archive_e::vsn' => 'root/SteveMusic', 'archive_e::file_owner' => 'ANY' }, 'archive_e' ); $VAR2 = bless( { 'archive_e::regex' => $VAR1->{'archive_e::regex'}, 'archive_e::file_group' => 'ANY', 'archive_e::name' => 'Movies', 'archive_e::criteria' => 'archive-e', 'archive_e::vsn' => 'root/Video', 'archive_e::file_owner' => 'ANY' }, 'archive_e' );

I cannot figure out why pusing the first struct into the @ap array works, but then when I push the new struct on top, it overwrites the original regex array from the first push, and puts junk in the regex portion of the second struct, but I'm probably doing something stupid. TIA for any suggestions...


In reply to Class::Struct problem by frontrange

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.