perl

recent posts related to the perl programming language

Perl - how to process each character in a string

I recently had to write some Perl code to process every word in a file, and that made me wonder how to process every character in a string. I didn't know how to do this, but I just cracked open my copy of the Perl Cookbook, and found a couple of possible solutions.

Perl uppercase and lowercase string conversion

Perl lowercase/uppercase string FAQ: How do I convert a string to uppercase or lowercase in Perl?

Perl next operator

Problem: You're writing code for a Perl loop, and you need to write some logic to skip over the current element in the loop, and move on to the next loop element.

Solution

When you're in a Perl for loop (iterating over an array or hash), and you want to move on to the next element in your array or hash, just use the Perl next operator, like this:

Perl loop - how to break out of a loop in Perl

Problem: You're writing some Perl loop code (for, foreach, or while), and you have a condition where you need to break out of your loop early. You quickly find out that Perl doesn't have a 'break' operator.

Perl string length

Perl string length FAQ: How do I get the length of a string in Perl?

To get the length of a string in Perl, use the Perl length function on your string, like this:

The Perl exists function - test to see if a hash key exists

Many times when working with a hash in Perl, you need to know if a certain key already exists in the hash. The Perl exists function lets you easily determine if a key already exists in the hash.

My "Perl hash" tutorials

I've recently written a number of articles about the Perl hash construct (or "Perl array hash"). In an effort to try to organize the Perl hash tutorials I've written, I've created this article to help link them all together.

Perl hash size - How to get the size of a hash in Perl

Perl hash size FAQ: How do I get the size of a hash in Perl?

Short answer: To get the size of a Perl hash, use the Perl keys function, and assign it to a scalar value, like this:

How to call a Perl subroutine (notes on the ampersand operator)

Recently I wrote a Perl subroutine tutorial, and a few people gave me grief over using the ampersand operator ("&") when calling my Perl subroutines. I'm not going to spend a lot of time on this, but I think it's important for people to know when they have to use the ampersand operator when calling their subroutines.

Perl hash - delete example

Perl Hash FAQ

Perl hash FAQ: How do I delete an element (a key/value pair) from a Perl hash? Also, how do I delete multiple elements from a Perl hash at one time?

Perl hash - delete an element by hash key

To delete an element from a Perl hash, use the Perl delete function. The general syntax of the Perl delete function looks like this:

Syndicate content