in reply to populate a hash, with limits set by user?
But all suggestions for improvement are very welcome. See, why I've choosen this name? :-)#!/usr/local/bin/perl use strict; $|++; my $input = 1; my %myhash; my @mykeys; my $key; print "enter names and values!\nleave name field emtpy and press 'Ente +r' when complete"; while ($input) { print "\nname :"; $input = <STDIN>; if ($input) { chop $input; next if (!$input); print "name already assigned" and $input=1 and next if ($myhas +h{$input}); while (!$myhash{$input}) { print "value :"; $myhash{$input} = <STDIN>; chop $myhash{$input}; } } } print "\n\nresults\n=======\n"; @mykeys = keys %myhash; foreach $key (@mykeys) { print "name :".$key." value: ".$myhash{$key}.". .\n"; }
|
|---|