in reply to Creating a Stringified Variable from a Data Structure
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!).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating a Stringified Variable
by Mandrake (Chaplain) on Dec 14, 2005 at 09:45 UTC |