substr

Perl CSV file column extraction

Perl CSV column data extraction FAQ: Can you share an example of how to extract one or more columns from a Perl CSV file or other similarly-formatted flat text file?

Perl is a terrific language for text processing, but several readers have written wondering about how to extract columns of data from text files with Perl. For instance, when you have a text database that looks like this:

Perl substr example - How to extract a substring from a string

Perl substring FAQ: How do I extract a substring from a string?

Solution: Use the Perl substr function. The general substr syntax looks like this:

$my_substring = substr($full_string, $start_pos, $length);

Perl substring example (substr)

A more specific Perl substring example is shown in the following code, where I extract the $firstname and $lastname strings from the $name string:

Perl substring - How to search for one string in another string

Perl substring FAQ: Can you demonstrate some Perl substring examples?

As a language, Perl is very good at text processing, including dealing with strings and substrings. In this article we'll take a look at some Perl substring manipulations we can perform.

For the purposes of our Perl substring tutorial, let's assume that we have a string defined like this: