use strict;
use warnings;
my %hash = ("no1"=>1,
"no2"=>2,
);
my @array = %hash;
print @array; #Output: no11no22
print "\n";
my $string = print @array;
print $string; #Output: no11no221
Why $string is not same as @ar开发者_如何学JAVAray? Why am I getting 1 at the end? What mistake am I making?
The main problem is that print
doesn't return a string, but rather prints out a string to a filehandle (see perldoc -f print
). Instead, you can let my $string=join('',@array);
When you assign the value of print you get the value of the variable being printed and the return code, 1 for sucess. See perldoc print
精彩评论