frontrange has asked for the wisdom of the Perl Monks concerning the following question:
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...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class::Struct problem
by choroba (Cardinal) on Aug 28, 2022 at 19:31 UTC | |
|
Re: Class::Struct problem
by frontrange (Novice) on Aug 28, 2022 at 20:04 UTC |