Hello dissident, and welcome to the Monastery!
The following line caught my eye:
filename => '@', # @ = array (of char) = string
The comment suggests you may have a misunderstanding. In C, a string is indeed an array of char (i.e., characters). But in Perl, a string is a scalar, not an array. So if you want a single filename, you should say:
filename => '$',
By the way, you might also want to have a look at MooX::Struct by the Monastery’s own tobyink.
Update: For example:
use strict; use warnings; use MooX::Struct Document => [ qw($fileID $filename @tags) ]; my $doc = Document[ 123, 'SampleFileName', [ qw(tag1 tag2 tag3) ] ]; printf "File ID: %s\n", $doc->fileID; printf "Filename: %s\n", $doc->filename; printf "Tags: %s\n", join(', ', @{ $doc->tags });
Output:
22:52 >perl 1068_SoPW.pl File ID: 123 Filename: SampleFileName Tags: tag1, tag2, tag3 22:52 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: How to allocate a struct?
by Athanasius
in thread How to allocate a struct?
by dissident
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |