J
Joe
Hello all,
Old C programmer here. Trying to pass a reference to a hash to a sub
routine in a module.
Have seen many posts about references, nothing seems to work in the case
of modules.
The following example currently returns the error:
Type of arg 3 to MYSTUFF:arseAssociative must be hash (not reference
construct
or) at main.pl line 9, near "%myListeners )"
Execution of main.pl aborted due to compilation errors.
I would like it to say:
L= adam, hello0
L= Nothing, hello1
L= Something, hello2
Here are the two files:
test.pl
------------------------------------------------
use MYSTUFF;
my %myListeners;
my $test1 = "Nothing";
my $test2 = "Something";
$myListeners{"adam"} = "Hello0";
MYSTUFF::myWorst( $test1, $test2, \%myListeners );
foreach $listener (sort(keys %myListeners)) {
print "L= $listener, $myListeners{$listener}\n";
}
exit;
------------------------------------------------
MYSTUFF.pm
------------------------------------------------
package MYSTUFF;
sub myWorst ($$\%) {
my ($first, $second, %refArray) = @_;
$refArray{$first} = "hello1";
$refArray{$second} = "hello2";
}
1;
Old C programmer here. Trying to pass a reference to a hash to a sub
routine in a module.
Have seen many posts about references, nothing seems to work in the case
of modules.
The following example currently returns the error:
Type of arg 3 to MYSTUFF:arseAssociative must be hash (not reference
construct
or) at main.pl line 9, near "%myListeners )"
Execution of main.pl aborted due to compilation errors.
I would like it to say:
L= adam, hello0
L= Nothing, hello1
L= Something, hello2
Here are the two files:
test.pl
------------------------------------------------
use MYSTUFF;
my %myListeners;
my $test1 = "Nothing";
my $test2 = "Something";
$myListeners{"adam"} = "Hello0";
MYSTUFF::myWorst( $test1, $test2, \%myListeners );
foreach $listener (sort(keys %myListeners)) {
print "L= $listener, $myListeners{$listener}\n";
}
exit;
------------------------------------------------
MYSTUFF.pm
------------------------------------------------
package MYSTUFF;
sub myWorst ($$\%) {
my ($first, $second, %refArray) = @_;
$refArray{$first} = "hello1";
$refArray{$second} = "hello2";
}
1;