Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^4: Creating hash with my imput

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

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

What I meant was exit the loop and print, sorry about the confussion. Although the extra code that you gave me just exits the loop and does not print the hash, how do I do this, byt the way thank you again

Replies are listed 'Best First'.
Re^5: Creating hash with my imput
by kejohm (Hermit) on Aug 19, 2011 at 04:25 UTC

    last should cause the script to drop out of the loop and continue. Maybe post the code that you have so we can see what the problem might be.

      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"; }

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2018-03-21 03:52 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (263 votes). Check out past polls.