package TestPackage; 2 use strict; 3 use warnings; 4 use Class::Struct; # include 5 6 struct( document => { 7 fileID => '$', # $ = scalar = int 8 filename => '@', # @ = array (of char) = string 9 tags => '@' # tags - array of strings 10 }); 11 12 # all of these three attempts to allocate memory fail: 13 #my $doc = document->new( ); # produces: Can't locate object method "fileID" via package "doc" (perhaps you forgot to load "doc"?) at testsnippet01. pl line 18. 14 #my $doc = new( 'document'); # produces: Undefined subroutine &main::new called at testsnippet01.pl line 12. 15 #my $doc = new( document); # produces: Bareword "document" not allowed while "strict subs" in use at testsnippet01.pl line 13. 16 17 my $doc = new document; # Hopefully a Perl saint knows what goes here... 18 19 $doc->fileID( 123 ); 20 $doc->filename( ['SampleFileName'] ); 21 $doc->tags( ['tag1', 'tag2', 'tag3'] ); 22 23 print "File ID: ", $doc->fileID, "\n"; 24 print "Filename: ", $doc->filename->[0], "\n"; 25 print "Tags: ", $doc->tags->[0], "\n";