Also, the "Main program" part of your program is not actually in package 'main' as it should be. It's actually running as part of the initialization of the last package declared, in this case 'module'. That can cause problems. Unless it's declared inside a { } block, a package declaration is in effect in your source code until the next package declaration. You could define package signal like this:my $object = { name => $name , port_list => [] , verilog_list => [] , signal_list => [] , instance_list => [] };
Note the use of the enclosing curly braces. Also, I used __PACKAGE__ in the bless call. I could have also just written bless $object;. If you plan to ever use class inheritance in your program, though, it's better to use the more conventional Perl style which explicitly passes the class as the first argument. You would call Signal->_define($type,$name,$width); instead of Signal::_define($type,$name,$width); and then _define would have another parameter:{ package Signal; sub _define{ my $type = shift ; my $name = shift ; my $width = shift ; if(($type ne "reg") && ($type ne "wire")) { printf("\n***** ERROR: Wrong Signal type %s\n",$type); exit(1); } my $object = { type => $type , name => $name , width => $width }; bless($object,__PACKAGE__); return $object; } sub print_defn { my $self = shift; printf("\t%s",$self->{type}); if(($self->{width})!=1) { printf("\t[%d:0]",($self->{width})-1) } else { print(" "); } printf("\t\t\t%s;\n",$self->{name}); } }
sub _define{ my $class = shift ; my $type = shift ; my $name = shift ; my $width = shift ; if(($type ne "reg") && ($type ne "wire")) { printf("\n***** ERROR: Wrong Signal type %s\n",$type); exit(1); } my $object = { type => $type , name => $name , width => $width }; bless($object, $class); return $object; }
In reply to Re: Problem in accessing array of objects.
by ReturnOfThelonious
in thread Problem in accessing array of objects.
by sumedhnarayan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |