How to auto generate values for a hash by giving an array or list elements as hash keys in perl?
Method 1:
%hash = map {$_=>1} "letcrackperl"=~/./g;
print %final;
Method 2:
%final = map { $_ => 1 } 1..5;
print %final;
Method 3:
@array=(9,2,3,4,3,6);
%final = map { $_ => 1 } @array;
print %final;
Method 4:
@array=(9,2,3,4,3,6);
@final{@array} = (1) x @array;
print %final;
Method 5:
@array=(9,2,3,4,3,6);
%final = map { $_,1 } @array;
print %final;
Method 6:
@array=(9,2,3,4,3,6);
%final = map { $_,1 } split(",",$line)
print %final;
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home