package crmtest;
use strict;
use warnings;
sub new {
my ($class, $env) = @_;
my @columns = ('one', 'two', 'three', 'four');
my $self = bless {
'env' => $env,
'column' => \@columns, # <-- Reference to an array given here
}, $class;
return $self;
}
sub add {
my ($self, $fields) = @_;
foreach my $field(@$self->{'column'}) { # <-- Not an ARRAY reference here
print $field . " -- " . $self->{'column'} . "\n";
# do stuff...
}
}
1;
####
use strict;
use warnings;
use lib('.');
use crmtest;
my $crm = crmtest->new('someenv');
my $cols = {
'col1' => 'something',
'col2' => 'anotherthing',
'four' => 'moretest',
};
$crm->add($cols);
####
my @columns = ('one', 'two', 'three', 'four');
my $ref = \@columns;
print @$ref;