demonking has asked for the wisdom of the Perl Monks concerning the following question:
Here my code: Note.pm:$VAR1 = bless({}, 'Note'); $VAR2 = bless({}, 'Note');
testNote.pl:package Note; use strict; use warnings; use Moose; use MooseX::Storage; with Storage('format' => 'JSON', 'io' => 'File'); has 'message' =>(is=> 'rw', isa =>'Str'); 1;
I think, that the problem is in this line:use strict; use warnings; use utf8; use feature 'say'; use Note; use Storable; use MooseX::Storage; use Data::Dumper; use JSON; my @container=(); my $obj = Note->new; $obj->message("firstmessage"); say $obj->message; push(@container,$obj); my $obj2 = Note->new; $obj2->message("secondmessage"); push(@container,$obj2); my @output=(); for my $counter (0 .. $#container){ push(@output,$container[$counter]->pack()); } say "Output packed strings:" ; for my $counter(0 .. $#output){ say $output[$counter]; } store \@output, 'saveNotes'; my @Notes=(); my @fin=@{retrieve('saveNotes') }; say "After reading file:"; @Arr=(); for my $counter (0 .. $#fin){ push(@Arr,Note->unpack($fin[$counter])); } say Dumper(@Arr);
Hope someone could help :)for my $counter (0 .. $#fin){ push(@Arr,Note->unpack($fin[$counter])); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Storing an array of Moose objects
by Anonymous Monk on May 29, 2013 at 07:15 UTC | |
by demonking (Novice) on May 29, 2013 at 09:10 UTC | |
by shmem (Chancellor) on May 29, 2013 at 12:07 UTC | |
by Anonymous Monk on May 30, 2013 at 00:37 UTC | |
|
Re: Storing an array of Moose objects
by Anonymous Monk on May 29, 2013 at 06:59 UTC |