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: Do not understand what line 4 and 5 does. Please help!: Edit Log



yoplocheo
Novice

Jan 7, 2016, 12:35 AM


Views: 1778
Do not understand what line 4 and 5 does. Please help!


Code
use warnings; 
my %dup=(); #creates empty hash
my @colours=qw(red blue red green yellow green red orange);
foreach my $color (@colours){
$dup{$color} = $dup{$color}+1;
}
printf "Color\tNumber of occurences\n";
while((my $key, my $value)=each %dup){
printf "%-12s%-s\n", $key, $value;
}
@colours = sort keys %dup;
print "Duplicates removed: @colours\n";

Can someone provide an indept explanation on whats going on on line 4 and 5:

Code
foreach my $color (@colours){ 
$dup{$color} = $dup{$color}+1;



(This post was edited by yoplocheo on Jan 7, 2016, 12:36 AM)


Edit Log:
Post edited by yoplocheo (Novice) on Jan 7, 2016, 12:36 AM
Post edited by yoplocheo (Novice) on Jan 7, 2016, 12:36 AM


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

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