in reply to Creating hash with my imput
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"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Creating hash with my imput
by rolandomantilla (Novice) on Aug 19, 2011 at 01:36 UTC | |
by kejohm (Hermit) on Aug 19, 2011 at 02:29 UTC | |
by rolandomantilla (Novice) on Aug 19, 2011 at 03:02 UTC | |
by kejohm (Hermit) on Aug 19, 2011 at 04:25 UTC | |
by rolandomantilla (Novice) on Aug 19, 2011 at 05:57 UTC | |
|
In Section
Seekers of Perl Wisdom