Know the two different forms of eval

Perl’s eval leads a double life, and, like Dr. Jekyl and Mr. Hyde, one is dangerous and one is almost safe. And, it’s important to know which one is dangerous; I grew up thinking that Dr. Jekyl was the bad one because evil people, such as Dr. No, had titles.

You can recognize the evals by their first, and only, argument. One form takes a string and the other takes a block. The string version compiles a string as Perl code and executes its, all at runtime. The block form runs, at run time, code that perl has already compiled. Continue reading “Know the two different forms of eval”

Know the phases of a Perl program’s execution

There are two major phases in the execution of a program run by Perl, which you sometimes see as “compile time” and “run time”, or sometimes now, “compile phase” and “run phase”. In the broadest of strokes, perl compiles code in the compile phase, and when it’s completely done with that, it moves on to the run phase, where it executes the code that it completely compiled. Continue reading “Know the phases of a Perl program’s execution”

Use Test::More as you experiment

When you’re trying something new, write small programs to test the idea or the new feature. This way, you isolate what you’re doing from the rest of the big application where you might want to use the idea. Some people try to insert the new features directly into the middle of their large programs, but then have problems separating the bugs from the rest of the application with the new thing they want to add. Continue reading “Use Test::More as you experiment”

Choose the right Perl version for you

When you’re paying attention to the Perl news about new Perl releases, you need to know which ones matter to you. It seems like a simple question, but there are many things to consider. Do you use an experimental or stable release? In a stable release, which of the supported versions should you use? What does your vendor provide? What does your manager let you use? Continue reading “Choose the right Perl version for you”

Choose the right Perl distribution for you

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”

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”

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”