There are several Perl distributions that you might choose, and each of them exists to serve a different audience. No one distribution is the right answer for you, and I can’t tell you which one to use without knowing about your situation and what’s important to you. Your possible solutions range from compiling, installing, and maintaining everything yourself to paying a support company to provide you with a compiled perl
and pre-compiled modules for easy installation. Continue reading “Choose the right Perl distribution for you”
Category: chapters
Use Data::Dump filters for nicer pretty-printing
Data::Dumper, a module that comes in the Standard Library, is one of the great tools knows to Perlers. You give it a big data structure and it pretty prints it for you. If you are one of those people who still believe that the best debugger in the world is print
and need to get data structures into a single string with decent formatting, something like Data::Dumper
is your best friend. When you get really complex data structures involving complicated objects, though, dumping the entire structure might be too much information. Continue reading “Use Data::Dump filters for nicer pretty-printing”
Know your sort orders
Once you leave the world of ASCII, things such as string comparisons and sorting get much tougher. In Effective Perl Programming, we devoted a short chapter to Unicode, but there’s a lot more that we could have covered. We mostly ignored the modern idea of locales and Unicode, but those have big effects on how Perl compares characters, and thus, how it orders them with sort
. Continue reading “Know your sort orders”
Build a new perl in parallel for fast results
When you get a new perl
, you want to use it right away. Why wait for all that pesky compiling? As soon as the new tarball hits CPAN, you want to download it and start playing with it. You can make that process a little faster by running a parallel make
. Continue reading “Build a new perl in parallel for fast results”
Use Regexp::Common to find locale-specific dates
[This is a mid-week bonus item, and it’s a bit of a departure from much of what you have already seen on this blog. This is just some code that I had to write this week and I thought you’d like to see it.]
I had to find some dates inside a big string, and the problem with dates is that there are some many ways to write them, and even if I get the format right, some of the machines might use another locale. My string comes from an ls
I run as a remote command, which might show the date in one of two formats. The files changed in the last six months replaces the year with the time: Continue reading “Use Regexp::Common to find locale-specific dates”
Know your character classes under different semantics
Now the Perl is Unicode aware (and, it’s been that way for a long time even if you haven’t been), you might have to be more careful in your regular expressions. Some of the character classes are much more inclusive than the ASCIIphile might imagine. In ASCIIland, character and byte semantics are the same thing. No matter which way you treat your strings you get the same answer. With Unicode, however, Perl might now treat certain sequences of bytes as one character. The character and byte semantics have diverged. If you let Perl treat your data as character data when it really isn’t, you can run into problems. If you aren’t already doing something special, you’re probably using character semantics. Continue reading “Know your character classes under different semantics”
Use the \N regex character class to get “not a newline”
Perl 5.12 introduced an experimental regex character class to stand in for every character except one, the newline. The \N
character class is everything but the newline.
In prior versions of Perl, this is the same thing as the .
meta character. That is, it’s the same as long as someone doesn’t add the /s
to the match or substitution operator or the regex quoting operator, or doesn’t insert the option inside the pattern: Continue reading “Use the \N regex character class to get “not a newline””
Create random strings
This Item isn’t really about random hex digits, but we thought we’d expand on an Item in the original Effective Perl blog that Joseph set up to support the first edition of Effective Perl Programming. He had an Item titled “Creating a String of Random Hex Digits”. We won’t reproduce it here, so you should read his version too. Continue reading “Create random strings”
Use a smart match to match several patterns at once
The smart match operator (Item 23. Make work easier with smart matching) reduces many common comparisons to a few keystrokes, keeping with Perl’s goal of making the common things easy. You can use the smart match operator to make even less common tasks, such as matching many regular expressions at the same time, just as easy. This Item shows you how to use the smart match to see if at least one of a series of regexes matches a string. Continue reading “Use a smart match to match several patterns at once”
Perl 5.14 adds non-destructive transliteration
[This is a mid-week bonus item since it’s so short]
In Perl 5.13.2, you got a non-destructive version of the substitution operator (Use the /r substitution flag to work on a copy). Instead of changing it’s target, the non-destructive version returns a new string that has the substitution. Continue reading “Perl 5.14 adds non-destructive transliteration”