QA

 <  Day Day Up  >  

Q&A

Q1:

Can you suggest a quick way to find a particular string in an array element?

A1:

Iterating over the array and checking each element are the usual ways to do so. If you frequently find yourself searching an array to see whether an element is in the array, you probably didn't want to store the data in an array in the first place. A much more efficient structure for random-element access is a hash, which is covered in Hour 7.

Q2:

How can I eliminate duplicate elements from an array?

How can I count the number of unique elements in an array?

How can I see whether two arrays contain the same or different elements?

A2:

The answer to all these questions is the same: Use a hash. Hashes allow you to do some rather interesting manipulations on arrays quickly and efficiently . All these questions are answered in Hour 7.

 <  Day Day Up  >  


SAMS Teach Yourself Perl in 24 Hours
Sams Teach Yourself Perl in 24 Hours (3rd Edition)
ISBN: 0672327937
EAN: 2147483647
Year: 2005
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net