Hash of Structs in a Package, is there an easier way?
From: Norman Ackroyd (deflatermouse_at_hotmail.com)
Date: 07/26/04
- Next message: vertigo: "string length"
- Previous message: Mark: "Undefined subroutine CGI::Vars"
- Next in thread: nobull_at_mail.com: "Re: Hash of Structs in a Package, is there an easier way?"
- Reply: nobull_at_mail.com: "Re: Hash of Structs in a Package, is there an easier way?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Jul 2004 07:22:07 -0700
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
- Next message: vertigo: "string length"
- Previous message: Mark: "Undefined subroutine CGI::Vars"
- Next in thread: nobull_at_mail.com: "Re: Hash of Structs in a Package, is there an easier way?"
- Reply: nobull_at_mail.com: "Re: Hash of Structs in a Package, is there an easier way?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]