perl

A Perl script to print Nagios log records in a human readable date format

Perl date FAQ: Can you share a Perl date example where you print a date in a decent human-readable format?

Update: Be sure to look at the comments below for some great Perl "one liners", i.e., one-line solutions to this problem.

In this blog I'll share the source code for a Perl program that takes nagios.logrecords as input, then outputs the records with a human-readable date format. More specifically, the input records look like this:

A Perl getopts example

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?")

A printf format reference page (cheat sheet)

Summary: This page is a printf formatting cheat sheet. I originally created this cheat sheet for my own purposes, and then thought I would share it here.

A cool thing about the printf formatting syntax is that the specifiers you can use are very similar, if not identical, between several different languages, including C, C++, Java, Perl, Ruby, and others, so your knowledge is reusable, which is a good thing.

How to read Perl command-line arguments

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

If you want to handle simple Perl command line arguments, such as filenames and strings, this tutorial is for you. If you want to handle command-line options (flags) in your Perl scripts (like "-h" or "--help"), this new Perl getopts command line options/flags tutorial is what you need.

Perl grep array FAQ - How to search an array/list of strings

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)

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.

CodeMee.com - A socially-tagged source code search engine

This announcement is a little premature, but ... for at least ten years I've thought about creating a search engine to make it easier to find source code examples, and while Google and thousands of writers have pretty much eliminated the need for such a search engine, I decided to create one anyway. The approach I'm working on is to create a source code search engine that is driven by "tags", in much the same way that del.icio.us and other tag concepts work.

Cato - A database CRUD assistant

I'm getting closer to releasing my "programming language independent" CRUD generator application. I'm now calling it Cato. My previous code names for it were Db2App and SideKick, but when I thought about the name SideKick, I couldn't help but think about Inspector Clousseau's trusty sidekick Cato Fong, and thus the application name was born. :)

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.

I just ran into a weird situation where a file I read into a Perl array was messed up, and some lines in the file had one form of "newline" character, and other parts of the file had some other type of newline character(s). The file looked fine in vi (even when I used "vi -b" to look at it), but if I read it in and spit it out with Perl, part of the output lines were messed up, and they all ended up printing as one long line.

Syndicate content