Hmm, I'm not sure I understand your question. Fixing the syntax errors in your code (s.below) makes it print out exactly what you seem to expect.
my %hash = ( 'mus09r' => [ '0,-464,AAACCATCTTGAAAC', '0,-350,GGTTCAGGATGGTTT', '0,-75,AAAACATCGTGACAC' ], ); while (my ($file,$val) = each %hash) { print ">dataset\n"; print "$file\n"; print ">instances\n"; print join("\n",@{$val}),"\n"; }
If what you're looking to do is put the text into a variable instead, simply append to that variable instead of printing directly.
use Data::Dumper; my %hash = ( 'mus09r' => [ '0,-464,AAACCATCTTGAAAC', '0,-350,GGTTCAGGATGGTTT', '0,-75,AAAACATCGTGACAC' ], ); my $string; while (my ($file,$val) = each %hash) { $string.=">dataset\n". "$file\n". ">instances\n". join("\n",@{$val}). "\n"; } print Dumper $string;
Update: Appending to string instead of replacing it every hash iteration, as per Mandrake's suggestion (note to self: Duh!).
In reply to Re: Creating a Stringified Variable
by tirwhan
in thread Creating a Stringified Variable from a Data Structure
by monkfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |