Perl Cd Bookshelf [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Perl Cd Bookshelf [Electronic resources] - نسخه متنی

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



5.15. Finding the Most Common Anything


5.15.1. Problem



You have an aggregate data structure,
such as an array or a hash. You want to know how often each element
in the array (or value in the hash) occurs. For instance, if your
array contains web server transactions, you might want to find the
most commonly requested file. If your hash maps usernames to number
of logins, you want to find the most common number of logins.

5.15.2. Solution


Use a hash to count how many times each element, key, or value
appears:

%count = ( );
foreach $element (@ARRAY) {
$count{$element}++;
}

5.15.3. Discussion


Any time you want to count
how often different things appear, you should probably be using a
hash. The foreach adds one to
$count{$element} for every occurrence of
$element.

5.15.4. See Also


Recipe 4.7 and Recipe 4.8



5.14. Presizing a Hash5.16. Representing Relationships Between Data




Copyright © 2003 O'Reilly & Associates. All rights reserved.

/ 875