In order to simplify some existing tools, I wanted to replace several arrays with an array of structs. So I made a simple example code to test the creation of the structs. The code used is as follows:
use strict;
use warnings;
#package Net_Node;
use Class::Struct Net_Node => [host => '$', access => '$', pass => '$'];
#struct( host => '$', access => '$', user => '$', pass => '$' );
my $example = new Net_Node;
$example->host('dir ip');
$example->access('TELNET');
$example->user('hjack');
$example->pass('buttstalion');
print "\n\n\n";
print "${example->host}\n";
print "${example->access}\n";
print "${example->pass}\n";
The issue is when I try to execute this script, I get this error:
Can't locate object method "host" via package "example" (perhaps you forgot to load "example"?) at test_2.pl line 15.
Can you please help me find out what do I need to correct??
Reading Class::Struct EXAMPLES, it looks like you need to call the struct function:
use warnings;
use strict;
use Class::Struct;
struct(Net_Node => [host => '$', access => '$', pass => '$']);
my $example = Net_Node->new();
$example->host('dir ip');
$example->access('TELNET');
$example->pass('buttstalion');
print $example->host, "\n";
print $example->access, "\n";
print $example->pass, "\n";
This prints:
dir ip
TELNET
buttstalion
Also, it seems $example->host won't interpolate inside double quotes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With