in reply to Required guidance to simplify this program
You got to look at or learn to use HASH.
Since you know how to use a for loop.
The following could help:
Hope it helps.#!/usr/bin/perl -w use strict; my @array = qw(John Sue Larry Mary John Mary Larry John Joe Lisa John +Mary); my %names; # create a hash variable to use for (@array) { $names{$_}++; } for ( keys %names ) { $names{$_} <= 1 ? print $_, ' is repeated for ', $names{$_}, ' time', $/ : print $_, ' is repeated for ', $names{$_}, ' times', $/; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Required guidance to simplify this program
by vyeddula (Acolyte) on Jun 04, 2013 at 06:17 UTC | |
by 2teez (Vicar) on Jun 04, 2013 at 06:29 UTC | |
by vyeddula (Acolyte) on Jun 04, 2013 at 17:47 UTC |