Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^6: Creating hash with my imput

by rolandomantilla (Novice)
on Aug 19, 2011 at 05:57 UTC ( #921150=note: print w/replies, xml ) Need Help??


in reply to Re^5: Creating hash with my imput
in thread Creating hash with my imput

Ok here is the code, is doing almost everything that I want ecxept for when I put exit I wanted to print the answer. For example put in my ID and my DNA X amount of times and them write exit and print out the hash. here is the code
#!/usr/bin/perl use strict; use warnings; my %hash; print ("put ID fallowed by a comma "," with the DNA for that ID\n\n"); chomp (my $in=<STDIN>); while ($in) { if ($in=~ /exit/i){ exit,} #Split the input on a coma 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^7: Creating hash with my imput
by kejohm (Hermit) on Aug 19, 2011 at 08:30 UTC

    Just replace exit with last and it should work the way you want it to, ie: if ($in =~ /exit/i){ last }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://921150]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-07-16 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (349 votes). Check out past polls.

    Notices?