Perl How-to Snippet Collection

Hi,

My name is Mihael Avram, I am a scientific researcher at the Technical University of Cluj-Napoca, Romania where I am working in software development and programming projects.

For those of you who are interested to see more examples, I created a series of how-to articles that offers you a large collection of snippets regarding the basic topics in Perl.

There are available more than 550 how-to articles, every article showing you a lot of tips and tricks to help you master the basic concepts of Perl scripting. The topics are meant to be used either by beginners or more advanced users.

The examples provided are inspired from tens of thousands of queries that I received from my visitors in more than 4 years of life of this site.

These articles are integrated both in a series of eBooks in PDF format as well as in a new site MPI - Perl Basics How to Tutorial where you can search through the whole thing.

1. The eBooks in PDF format


At this time six eBooks are available :

Perl Scalar and String Functions - How To Tutorial

Some of the topics described in this eBook are listed below:
  • How to use the chomp function to remove the ending newline from an input string
  • How to manipulate or query information about a string
  • How to master data conversions from a format to another
  • How to use the scalar and string functions with different statements, special variables and operators
  • How to use the scalar and string functions with the regular expressions
  • How to use the scalar and string functions with simple or multidimensional arrays or hashes, with complex data structures
and much more.

To see what I mean, I suggest you to take a look at the Table of Contents of this eBook.

Perl Functions for Real Arrays - How to Tutorial

Some of the topics described in this eBook are listed below:

  • How to use pop, push, shift and unshift with a stack array
  • How to use pop, push, shift and unshift with a queue array
  • How to emulate a circular list with pop, push, shift and unshift
  • How to use the real array functions with different statements, special variables and operators
  • How to use the real array functions with arrays and lists or with more complex data structures like arrays of arrays, arrays of hashes and hashes of arrays
  • How to use the real array functions with matrices
  • How to use the real array functions with @_, @ARGV, @$_, %{}, ||, &&, =>, @{}, [], $_
and much more.

To see what I mean, I suggest you to take a look at the Table of Contents of this eBook.

Perl Functions for List Data - How to Tutorial

Some of the topics described in this eBook are listed below:

  • How to use grep as a filter, counter or finder
  • How to use grep and map vs foreach
  • How to use sort with different aggregates
  • How to use the list data functions with different statements, special variables and operators
  • How to use the list data functions with arrays, hashes and lists or with more complex data structures like arrays of arrays, arrays of hashes, hashes of arrays or hashes of hashes
  • How to use the list data functions with matrices
  • How to use the list data functions with @_, @$_, %{}, ||, &&, =>, @{}, [], $_
and much more.

To see what I mean, I suggest you to take a look at the Table of Contents of this eBook.

Perl Functions for Real Hashes - How to Tutorial

Some of the topics described in this eBook are listed below:

  • How to use delete with hashes or arrays
  • How to use exists with arrays, hashes or subroutines
  • How to use the real hashes functions with grep, map and regular expressions
  • How to use the real hashes functions with different statements, special variables and operators
  • How to use the real hashes functions with arrays, hashes and lists or with more complex data structures like arrays of hashes, hashes of arrays or hashes of hashes
  • How to use the keys and values functions to traverse hashes
  • How to use the real hashes functions with @$_, %{}, ||, &&, =>, @{}, [], $_, $"
and much more.

To see what I mean, I suggest you to take a look at the Table of Contents of this eBook.

Perl Complex Data Structures - How to Tutorial

The topics described in this eBook include: arrays of arrays, arrays of hashes, hashes of arrays, hashes of hashes or other complex data structures.

For every data structure are given examples about how to:

  • generate, access, print, append, insert, remove, replace, sort, copy, search or filter its elements
  • iterate through it using (nested) while, for, foreach, map or grep
  • deal with autovivification
  • use recursive subroutines
  • use it with special notations as @$_, %{}, ||, &&, =>, @{}, [], $_, $"
and much more.

To see what I mean, I suggest you to take a look at the Table of Contents of this eBook.

Perl Statements How To Tutorial

Some of the topics described in this eBook are listed below:

  • How to use the conditional statements: if, unless, switch
  • How to use the loop statements: for, foreach, while, do-while, until, do-until; a special attention is accorded to the foreach and while statements, being provided a lot of examples to illustrate their use
  • How to use compound statements, loop controls and statement modifiers
  • How to use the statements with different functions or operators
  • How to use the statements with the regular expressions
  • How to use statements with simple or multidimensional arrays or hashes, with complex data structures
and much more.

To see what I mean, I suggest you to take a look at the Table of Contents of this eBook.


2. MPI - Perl Basics How To Tutorial


Through this new site you have access to all my articles, including the search option. The following topics are covered at the moment:
  • How to use operators
  • How to use the scalar and string functions
  • How to use functions for real arrays
  • How to use functions for list data
  • How to use functions for real hashes
  • How to use complex data structures (including arrays of arrays, arrays of hashes, hashes of arrays and hashes of hashes)
  • How to use statements
  • A lot of other topics including examples of using regular expressions, creating and printing text/binary files, using special operators and so on
Searching through these articles you can benefit of:
  • for almost all the topics you find interesting and complete examples about why, how and where you can use these topics in a Perl script
  • there are supplied detailed explanations for every topic in order to better understand how to use it
  • for every function I present the syntax forms and a brief description necessary to help you better understand how to use it
  • detailed examples are supplied for the main situations in which you can use a specific topic; in the same time are shown alternatives to do the same thing by using other functions or topics (see the Perl motto: “there’s more than one way to do a thing in Perl”)
  • where it was possible, I compared some topics against others in order to point out the differences and similarities between them (for example foreach versus while, foreach versus map or grep, etc)
  • a large number of examples to help you use the data types in Perl, including the “multi-dimensional” structures
  • you can explore the site using search; I optimized each article to contain the relevant words for the topic described in – for example if you search using the AoA word you’ll get almost all the articles that have to do in some way with arrays of arrays; or you can use more words to refine the search
  • it saves hours of your valuable time you usually use to surf the Internet after information

You can do a lot of things there, here is an excerpt from the article "How to use map to traverse a hash of hashes":



Click here to see all the stuff



 Testimonials 

 John R Jones  Northridge, CA USA wrote:

The eBook I purchased, "Perl Complex Data Structures", was very helpful; so much so that I would like to order the rest of the set.

Having a running example in it's simplest possible form with a clear explanation is a tremendous help in putting the concepts learned elsewhere to work. The format is efficient, with little of the fluff found in other textbooks.

These books are truly a "How-To" bible for advanced Perl topics. Until I read "Perl Complex Data Structures", I had approached problems in a simplistic fashion. This material gave me the knowledge to write programs in less time that were both shorter and faster. After I started using some of the more advanced techniques presented in the book, explanations I had read in other books started to make sense. I might have read about these "tricks" elsewhere, but I didn't consider using them in my programs until I read this eBook. I feel much more confident in tackling the more sophisticated programming problems.

Although I would consider the book fairly advanced, the straight forward explanations make the material accessible to programmers of modest experience. That being said, if this is your very first attempt at Perl, you will need to start with a beginning text, such as "Learning Perl". Once that makes sense, these eBooks will take your skills to the next level.


 Miriam L Caballero  Mountain View, CA USA wrote:

Hi,

Yes I did find your perl ebook very resourceful. I'm taking an Intro Programming Perl class at the local community college and I needed more examples to understand the concepts more clearly. I searched the internet and found your Perl ebooks package - How to Tutorial 2. I purchased the package and used the ebooks immediately. Even though I had the O'Reilly Learn Perl book for class, your ebooks helped me tremendously. It added another layer to my learning perl.

I would definitely recommend the Perl Package to anyone who is picking up Perl for the first time or even as a quick reference guide on your laptop or desktop.

p/s Another ebook idea would be to add an intro to programming structure. I attended programming structure class many moons ago and like they say if don't use it you loose it. Well I had to relearn the programming structures again and I didn't find any real help on the internet.

Keep up the great work and yes a free membership to your website would be great.

Thanks !


 Kenneth Burrell  MA, United States wrote:

I'm Java/C# programmer for many years .. when I also inherited 1000's of lines of production Perl code. So like most languages, once you get comfortable with the syntax, reading the seminal books, you start to build your toolbox and then rely on "code snippet" books to refine ideas, or get deeper into more specialized aspects of the language when the project requires it.

I can't even remember how I found your link .. but from the myriad of Perl ones I cycle through ... your books are not unlike the way I try to organize snippets, around language features, and applications .. but yours are much more complete, and thorough. I'm continually amazed at the power of applying the Perl scalars, lists, and hashes model to any problem. I remember back in the day when Larry Wall won a Dr Dobbs award, and I wondered what the hoopla could possibly be about, after all I was an aspiring high level language programmer, how hard could scripting be? .. its now, many years later that I can now say that I understand...

Your books, taken as a whole, are probably the best snippet based collection that I've seen for Perl .. Can't wait for the hash addition. If you're still in the Perl space, it would be cool to see some snippets based on more functional aspects, modules, and dynamic code blocks, which is where I tend to take my Perl code currently ...


 Harley Jones  OR, United States wrote:

Just a reply to let you know that I appreciate that you provided a free download of your perl book ... Next in line was the question of just how the product differed from any other book or website for usefulness. I purchased the $10 book, and am still looking it over now. I really like the concept of a list of 'how-to's" that will hopefully save me some time looking up such items on the internet.