and returns:#!/usr/bin/perl -w use strict; my $argument=10; my %hash = sub_returning_hash($argument); print "a = "; print $hash{"a"}; print "\n"; print "b = "; print $hash{"b"}; print "\n"; print "c = "; print $hash{"c"}; print "\n"; sub sub_returning_hash { my $argument=shift; my $a=$argument+1 ; my $b=$argument+2 ; my $c=$argument+3 ; my %output_record = ( "a" => "$a", "b" => "$b", "c" => "$c" ); return %output_record; } # sub_returning_hash
Now I want to execute the subroutine as a thread, so I try:a = 11 b = 12 c = 13
but I receive:#!/usr/bin/perl -w use strict; use threads; my $argument=10; my $thr = threads->new(\&sub_returning_hash, $argument); my %hash = $thr->join; print "a = "; print $hash{"a"}; print "\n"; print "b = "; print $hash{"b"}; print "\n"; print "c = "; print $hash{"c"}; print "\n"; sub sub_returning_hash { my $argument=shift; my $a=$argument+1 ; my $b=$argument+2 ; my $c=$argument+3 ; my %output_record = ( "a" => "$a", "b" => "$b", "c" => "$c" ); return %output_record; } # sub_returning_hash
I tried the same returning a scalar instead of an hash, and it works fine. Any suggestion to be able to access the hash returned by the subroutine when running as a thread? Thanks!Odd number of elements in hash assignment at test.pl line 8. Use of uninitialized value in print at test.pl line 9. a = Use of uninitialized value in print at test.pl line 10. b = Use of uninitialized value in print at test.pl line 11. c =
In reply to Threads that return hash by hilbert
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |