For starters, you should probably be using strict and warnings to catch any errors in your script.
You are only prompting for input once. Instead you need to get input inside a loop.
You code @DNA = $id doesn't split the input into ID and DNA automatically; you need to use the split() function to do that.
Here is an example that should do what you want (untested):
#!/usr/bin/perl usr strict; use warnings; my %hash; print "put ID followed by a comma with the DNA for that ID\n\n"; chomp(my $in = <STDIN>); while($in){ # Split the input on a comma into a maximum of two fields my($id,$dna) = split m/,/, $in, 2; $hash{$id} = $dna; print "Please enter another ID and DNA\n"; chomp($in = <STDIN>); } # Print hash contents while(my($key,$value) = each %hash){ print "$key -> $value\n"; }
In reply to Re: Creating hash with my imput
by kejohm
in thread Creating hash with my imput
by rolandomantilla
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |