Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to find number of unique elemenst in array

by Skeeve (Parson)
on Nov 27, 2008 at 22:33 UTC ( [id://726495]=note: print w/replies, xml ) Need Help??


in reply to How to find number of unique elemenst in array

My constraint: Don't use a hash!

my @array = qw/A B C B D B D/; my $c=1; foreach my $k (sort @array) { next if --$c; $c= scalar grep { $_ eq $k } @array; print "There are $c element(s) of $k\n"; }

Update: Fixed thanks to gashos coment.


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^2: How to find number of unique elemenst in array
by gasho (Beadle) on Dec 01, 2008 at 18:45 UTC
    It failed test with my @array = qw/history historyA historyB history historyA D/;
    (: Life is short enjoy it :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://726495]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-24 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found