I am gradually trying to use code that reads lines from a delimited pipe, breaks each one and assigns it to the hash using a hash fragment.
I turned the hash into a Moose class, but now I have no idea how to quickly assign fields from a file to class attributes (if at all).
I know that I just can simply do:
my $line = get_line_from_file; my @fields = split /\|/, $line; my $record = My::Record->new; $record->attr1($fields[0]); ...
but I was hoping that a fast one liner would assign all the attributes at once, somewhat akin to:
my $line = get_line_from_file; my %records; @records{@field_names} = split /\|/, $line;
I read about coercion, but from what I can say, not what I need.
Is it possible?
thanks
perl attributes moose
Sparkles
source share