recent posts related to the perl programming language

A Perl script to parse a CSV file, skip lines, pattern match alvin June 30, 2016 - 8:40am

This is a little Perl script I wrote to parse a CSV file I periodically download from Google AdSense. It does the following things:

A Perl script to delete binary files alvin June 28, 2016 - 10:24am

As a quick note and a little bit of source code sharing, I wrote the following Perl script to delete all of the binary files it finds in a list of files it’s given. I named this script, and it should be called like this: listOfFilesToLookAt

where listOfFilesToLookAt is a file that contains a list of filenames, with one filename per line.

Given that brief introduction, here’s the source code:

A Perl getopts example alvin November 2, 2012 - 7:16pm

Perl getopts FAQ: Can you demonstrate how to use the getopts function? (Also written as, "Can you demonstrate how to read Perl command line arguments?")

How to read Perl command-line arguments

Perl FAQ: How do I read command-line arguments in Perl?

Note: If you want to handle simple Perl command line arguments, such as filenames and strings, this tutorial shows how to do that. If you want to handle command-line options (flags) in your Perl scripts (like -h or --help), my Perl getopts command line options/flags tutorial is what you need.

Perl grep array FAQ - How to search an array/list of strings alvin May 20, 2011 - 2:32pm

Perl "grep array" FAQ: Can you demonstrate a Perl grep array example? (Related: Can you demonstrate how to search a Perl array?)

A very cool thing about Perl is that you can search lists (arrays) with the Perl grep function. This makes it very easy to find things in large lists -- without having to write your own Perl for/foreach loops.

Regular expression examples (common regex patterns) alvin May 4, 2011 - 11:23am

Regular expression FAQ: Do you have a list of common regular expression examples, i.e., the most common regex patterns used in programming languages like Java, Perl, PHP, Ruby, and others?

I've been asked several times, so I thought it might be helpful to post some of the most common regular expression examples that are used in programming. Honestly I haven't tested any of these yet -- I did them off the top of my head -- but I think they will work for most open source programming languages.

A Perl “write to file” example

Perl write to file FAQ: Can you demonstrate an example of how to write to a file in Perl?

Somehow I managed to go all these years without showing a simple Perl "write to file" example. Let's fix that.

Perl “write to file” example

Here's a short snippet of code that shows how to write to a file in Perl:

A Perl array chomp example

Summary: How to use the Perl array chomp syntax to chomp every element in a Perl array.

Perl and Apache - How to parse Apache access log file records in Perl

Perl Apache log file FAQ: Can you demonstrate how to read an Apache access log file in Perl (How to parse an Apache access log file in Perl)?

I've provided Perl examples before that can be used to read and parse an Apache log file ("How many RSS feed readers do I have?", "A Perl program to read an Apache access log file"), but to make this code a little easier to find, I'm breaking that code out here.

A Perl array 'contains' example

Perl array FAQ: How can I test to see if a Perl array already contains a given value? (Also written as, How do I search an array with the Perl grep function?)

I use the Perl grep function to see if a Perl array contains a given entry. For instance, in this Perl code: