#!/usr/bin/perl -w # gene.plx # use strict; my %hash = (); while () { chomp($_); my ($dept,$email)=split(/:/); $hash{ $dept } .= $email.','; } s/,\z// for values %hash; print "\n"; while ( my ($key, $value) = each(%hash) ) { print "$key => $value\n"; } print "size of hash: " . keys( %hash ) . ".\n"; print '-' x (60),"\n"; __DATA__ 6:car 1:human 3:fruits 9:flower 2:flower 5:human