Perl
  Home arrow Perl arrow Perl Lists: A Final Look at List::Util
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PERL

Perl Lists: A Final Look at List::Util
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    PERL ARTICLES

    - More Perl Bits
    - Perl, Bit by Bit
    - Basic Charting with Perl
    - Using Getopt::Long: More Command Line Option...
    - Command Line Options in Perl: Using Getopt::...
    - Web Access with LWP
    - More Templating Tools for Perl
    - Site Layout with Perl Templating Tools
    - Build a Perl RSS Aggregator with Templating ...
    - Looping, Security, and Templating Tools
    - Perl: Bon Voyage Lists and Hashes
    - Templating Tools
    - Perl: Number Crunching
    - Perl Debuggers in Detail
    - Debugging Perl





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek