Perl
  Home arrow Perl arrow Perl Lists: Utilizing 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: Utilizing List::Util
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-14

    Table of Contents:
  • Perl Lists: Utilizing List::Util
  • First Up On the Block
  • Making First a Little More Complicated
  • Max()ing It Out
  • My String is Bigger Than Yours: The MaxStr(List) Story

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Perl Lists: Utilizing List::Util
    (Page 1 of 5 )

    In this fifth part of our series on Lists, we will cover the List::Util module, which gives us seven handy-dandy subroutines with which to manipulate our lists. If we have time, we'll also cover multi-dimensional lists in more depth (we briefly covered them in an earlier article).

    In our previous article we discussed, in large part, the split() function and its many uses. As those of you who read that article will recall, the split() function's main purpose is to take a string, break it apart, and return a list full of strings. There were many ways to do this and I think we covered the lion's share of them. Finally, we also went over how to assign a list to another list. And another list. And so forth.

    Before we begin talking about the first of our new subroutines, the first{BLOCK}List, let's look at a table describing what each of the seven do:


    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.

    Before you begin tackling these examples, take note: you must add the following line to your code when using these subroutines. You add it near the top and you have to include any subroutine you plan on using throughout your program:


    Use List::Util qw(first max maxstr);

    If you were going to also use shuffle, you would write:


    Use List::Util qw(first max maxstr shuffle);

    and so forth. This tells the interpreter that you are going to use: first, max, maxstr, and shuffle in your program.

    More Perl Articles
    More By James Payne


       · Thanks for stopping by for another episode in our continuing look at Hashes and...
     

       

    PERL ARTICLES

    - Perl: A Continuing Look at Hashes and Multid...
    - 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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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