Hash of Structs in a Package, is there an easier way?

N

Norman Ackroyd

Ok, so I'm working on a Perl proggy to convert Net.Data to JSP (gotta
love Perl.) I've got a Module that has a Class to store all relevant
information about a Net.Data user defined function that is read in. In
this class is a Hash of a Struct where the key is the variable name
and the Struct itself contains the variable type and value:

package ND2Parse::Function;

use Carp;
use Class::Struct;

struct Var => {
type => '$',
value => '$',
};

sub new
{
my $classname=shift;
my $functionname=shift;
my $self={
vars => {},
name => $functionname
};
bless($self,$classname);
return $self;
}

sub addvar
{
my $self=shift;
my $var=shift;
my $type=shift;
my $value=shift;
unless ($var)
{
carp "No var name passed in ->addvar(<var>,<type>,<value>)\n";
return 0;
}
${$self->{vars}}{$var}=Var->new();
${$self->{vars}}{$var}->type($type) if $type;
${$self->{vars}}{$var}->value($value) if $value;
return 1;
}


My question: Is there an easier/cleaner/more readable way to reference
and update the Struct other than what I'm doing:

${$self->{vars}}{$var}=Var->new();
${$self->{vars}}{$var}->type($type) if $type;
${$self->{vars}}{$var}->value($value) if $value;

Specifically, this portion seems rather unwieldy to me:

${$self->{vars}}{$var}


Any thoughts would be appreciated.

-Norm
 
N

nobull

(e-mail address removed) (Norman Ackroyd) wrote...
[...] this portion seems rather unwieldy to me:

${$self->{vars}}{$var}

Yeah, it usually written using the shorthand:

$self->{vars}{$var}

This newsgroup does not exist (see FAQ). Please do not start threads here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top