Do not be fearful of the monks , they are so amiable
Here is a working copy of your code.
First thing to do is read perldoc Class::Struct
Using an editor with color coding can help u catch trival issues in perl like doc as opposed to $doc.
you will also be greatly benefitted by reading perldoc perlreftut to understand how references work.
coming back to perl after many years, i realise the key to understanding a language is through its basic data structures, so perldoc perldata / perldsc and perlvar are your manual until you reach the level of proficiency
package TestPackage; 2 use strict; 3 use warnings; 4 use Class::Struct; # include <structs> 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 m +ethod "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" n +ot 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";
Do not wait to strike when the iron is hot! Make it hot by striking - WB Yeats

In reply to Re: How to allocate a struct? by perlron
in thread How to allocate a struct? by dissident

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.