Perl
  Home arrow Perl arrow Perl Lists: A Final Look at List::Util
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Perl Lists: A Final Look at List::Util
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-21

    Table of Contents:
  • Perl Lists: A Final Look at List::Util
  • Min(List)...Your Guide to Minimalism
  • MinStr(List) Like Them Small
  • Do the Shuffle

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Perl Lists: A Final Look at List::Util
    (Page 1 of 4 )

    Welcome to the sixth part of our series on Perl Lists. Here we will cover the remaining four List::Util subroutines: min(list), minstr(list), shuffle(list), and sum(list). We'll learn how to manipulate lists using these subroutine in various intended and unintended ways.In our previous article we discussed the first{block}List subroutine, which returned the first value in a list. It also could be used to return the first value in a list that met a specific criteria, such as the first value greater than "x" or the first value greater "x" but less than "y," and so forth. We also covered max(List), which finds and returns the maximum numeric value in a list, and maxstr(List), which find the maximum string value in a list. We learned that, where Perl is concerned, "z" is greater in value than "Z," "A," and "a."

    Before we begin covering the last of our subroutines, let's take a final look at the List::Util table:

     

    Subroutine

    What It Does

    first{BLOCK}List

    Used to return the first value in a list. You can also use conditionals to return the first value in the list that matches your criteria.

    max(List)

    Used to retrieve the largest number in a list.

    maxstr(List)

    Used to return the largest string value in a list.

    min(List)

    Used to return the smallest number value in a list.

    minstr(List)

    Used to return the smallest string value in a list.

    shuffle(List)

    Used to retrieve the list in an order that is random.

    sum(List)

    Used to add the numbers in a list and return the value.

    Also remember that before you can use any of the List::Util subs, you must include them near the top of your code, like so:


    use List::Util qw(maxstr);

    And you must make sure to include whatever subroutines you are going to use in your program in the parameters of qw(). For example:

    use List::Util qw(minstr sum min shuffle);

    would allow you to use the minstr, sum, min, and shuffle subroutines.

    More Perl Articles
    More By James Payne


       · Thanks for stopping by for another article in our series on Perl Lists and Hashes....
     

       

    PERL ARTICLES

    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util
    - Perl Lists: Utilizing List::Util
    - Perl Lists: The Split() Function
    - SQL and CGI with Perl and DBI
    - Perl Lists: More Functions and Operators
    - SELECT Queries and Perl
    - Perl Lists: More on Manipulation
    - Creating a Database with Perl and DBI
    - Perl: Sailing the List(less) Seas
    - Perl and DBI
    - Perl: Concatenating Text and More
    - Perl Text: Quoting Without Quote Marks
    - Perl: Releasing Your Inner Textuality




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway