in reply to Stumped on an OO Problem
The keys of the _permitted element in your object are being used to index into the $self hash to extract the values. The problem with this is that you don't know what order the keys are going to come out. To solve that, I would suggest doing the initialization thusly:sub pack { my $self=shift; my $record=join(':', @{$self}{keys %{$self->{_permitted}}}); return $record; }
And then assign %fields to _permitted as before. But now you have also the @permitted array, which would allow you to write pack as follows, giving you control over the order in which the elements are packed:my @permitted=qw(name price description); my %fields; @fields{@permitted}=undef;
sub pack { my $self=shift; my $record=join(':', @{$self}{@permitted}); return $record; }
--ZZamboni
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Stumped on an OO Problem
by btrott (Parson) on Jun 27, 2000 at 22:50 UTC | |
by ZZamboni (Curate) on Jun 27, 2000 at 23:11 UTC |