CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [PerlBeginner1] Help with Hashes: Edit Log



g4143
Novice

Apr 21, 2013, 5:23 PM


Views: 299
Re: [PerlBeginner1] Help with Hashes

Won't it make more sense to set your loop up like...


Code
#!/usr/bin/perl 

use warnings;
use strict;

while ( <STDIN> )
{
chomp;
print $_, "\n";
}


A more complete solution would look something like this..

Code
#!/usr/bin/perl 

use warnings;
use strict;
use feature qw/state/;

my %hash = (Mike => '32', Kevin => '43', Dave => '19');

while ( <STDIN> )
{
chomp;
next if exists $hash{$_};

print "enter age->";
chomp(my $age = <STDIN>);
$hash{$_} = $age;
}

foreach(sort(keys(%hash)))
{
state $line_no;
print ++$line_no, ": $_ has a value->$hash{$_}\n";
}



(This post was edited by g4143 on Apr 21, 2013, 5:31 PM)


Edit Log:
Post edited by g4143 (Novice) on Apr 21, 2013, 5:31 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives