Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Google   


Introduction to Perl for Unix System Administrators

(Perl without OO and excessive complexity)

by Dr Nikolai Bezroukov


Chapter 3: Perl Data Structures

Version 0.72(beta)

Contents

3.1. String operations

3.2. Operations on Arrays

3.3. Operations on Associative Arrays

3.4. Summary

3.5. Homework


Perl supports several types of data structures: 

Another way to look into data structures is to analyze their strength and weaknesses

All in all Perl provide a rich set of built-in operation for lists and associative arrays (hashes).  It also provides some connections between these two data structures. Here Perl is really one of the top if not the top language in existence. If you task can be structured of information along these lines (text processing) you can immensely benefit from using Perl.

At the same time multidimensional arrays are not natural to Perl and if your task does require them you probably will be in disadvantage and should consider either using references or switch to other language that supports this abstraction better.

Perl warts

While in many way a very innovative language Perl suffers from some design decisions connected with using separate sets of build-in functions for strings and arrays:

The main problem with Perl that I see is the although it provides a rich set of functions for string and arrays they are not generalized in such a way that similar functions are applicable to both without renaming, although this is entirely possible. So instead of substr functions (that is defined on strings) you need to use splice function for arrays and remember idiosyncrasies of two functions instead of one. Here Larry Wall made a very bad decision, but we can do nothing about it. You will see the problem yourself after you will face the assortment of functions that are available in Perl for arrays and strings. Actually you are forced to use a subset as full assortment is beyond human capacities to master (starving in the food store effect ;-).


Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Created: November 7 1998; Last modified: March 15, 2008