Home arrow Perl Programming arrow Perl Lists: A Final Look at List::Util

Perl Lists: A Final Look at List::Util

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.

TABLE OF CONTENTS:
  1. Perl Lists: A Final Look at List::Util
  2. Min(List)...Your Guide to Minimalism
  3. MinStr(List) Like Them Small
  4. Do the Shuffle
By: James Payne
Rating: starstarstarstarstar / 3
April 21, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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 Programming Articles          >>> More By James Payne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PERL PROGRAMMING ARTICLES

- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: