perl - Printing hash values -
i have set of hash values arrays same number of elements. printing below each other, want print them next each other.
in output below, columns starting clakin_p, clkin_n , phy2clb_scan_out different arrays diff values of hash , supposed next each other.
for ( $m = 0; $m <= ($#pin_names); $m++ ) { ( $n = 0; $n <= ($#output); $n++ ) { if ( $pin_names[$m] eq $output[$n] ) { print "$hash{$n}\n"; } } }
current output :-
clkin_p 1 1 clkin_n 0 0 phy2clb_scan_out h h
your statement print "$hash{$n}\n";
includes newline character @ end (\n
). causes each hash value printed on separate line. remove newline.
also, traditional for
loops maintain track of iterator needed in perl , potential source of mistakes in code. much improve this:
foreach $pin (@pin_names) { foreach $out (@output) { if ( $pin eq $out ) { print "$hash{$n} "; } } }
perl hash key-value
No comments:
Post a Comment