removing excess tab from loop in perl -


a basic question involving loops. if i'm doing basic loop want generate tab delimited table hash of hashes (format: $hash_of_table_data{$headers}{$entry} = 1) example code:

foreach $rowheader (keys %hash_of_table_data) {   print "$rowheader\t";   foreach $entry (keys %{ $hash_of_table_data{$rowheader}}) {     print "$entry\t";   }   print "\n"; } 

so, doing loops this, @ end of print last element of each row, have tab. there simple way generate similar list wouldn't add tab @ end? or simple chomp function remove last tab added prior doing new line? (i want add tabs between every element, except final element).

as people have commented, join seems nice solution problem. can in single line:

print join("\t", $_, keys %{$hash{$_}}) . "\n" foreach keys %hash; 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -