in reply to How to allocate a struct?
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to allocate a struct?
by dissident (Beadle) on Oct 28, 2014 at 13:28 UTC | |
by perlron (Pilgrim) on Oct 28, 2014 at 14:36 UTC | |
by dissident (Beadle) on Oct 28, 2014 at 21:10 UTC | |
by BrowserUk (Patriarch) on Oct 28, 2014 at 21:20 UTC | |
by dissident (Beadle) on Oct 28, 2014 at 22:58 UTC | |
|