use strict; use warnings; # Create a Document struct with all elements writeable: use MooX::Struct -rw, Document => [ qw( $fileID $filename @tags ) ]; # Create two documents and put them in an array; my $doc = Document[ 1, "PetsFile"]; my $doc2 = Document[ 2, "BirdsFile", ['Doves', 'Eagles']]; my @doc_list = ( $doc, $doc2 ); # Change the tags on both documents to prove they're writeable $doc_list[0]->tags( [qw(Cats Dogs)] ); push @{$doc2->tags}, 'Shantaks'; # Display the result. Notice that array indexes start at 0! for (0..1) { printf "File ID: %s\n", $doc_list[$_]->fileID; printf "Filename: %s\n", $doc_list[$_]->filename; printf "Tags: %s\n", join(', ', @{$doc_list[$_]->tags}); print "\n"; } # But here is a nicer way, without indexes: for my $d (@doc_list) { printf "File ID: %s\n", $d->fileID; printf "Filename: %s\n", $d->filename; printf "Tags: %s\n", join(', ', @{$d->tags}); print "\n"; }