perl

recent posts related to the perl programming language

How to parse Apache access log file records in Perl

Perl FAQ: Can you show 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?

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

A Perl trim function

Perl string FAQ: Is there something like a "trim" function in Perl, similar to the Java trim function, which trims leading and trailing whitespace characters from a string?

My Perl skills aren't exactly up to date these days, but in days gone past there was no Perl trim function. So, somewhere along the way I wrote one. Here's the source code for my Perl trim function:

How many RSS readers do I have?

Website FAQ: How many RSS subscribers do I have on my website?

Like many other people with a blog or website, I was curious yesterday about how many RSS readers/subscribers the devdaily website has. You can try to get this information in a variety of ways, but the real information is on your server, in your Apache log files.

To figure out how many RSS subscribers your website has, just go through your Apache log file, find all the records that look like this:

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.

Syndicate content