The evolution of character class shortcuts

Character class shortcuts used to be easy because ASCII was easy. Either of those were easy if ASCII was what you wanted, but quite limiting otherwise. Perl v5.6 introduced Unicode support and the world started to change.

evolution

A good programmer is always trying to eliminate ambiguity. Their code should work the same way everywhere, but character class shortcuts can’t guarantee that anymore. I wrote about these a bit in Know your character classes for The Effective Perler.

Continue reading “The evolution of character class shortcuts”

DOS pattern matching, in Perl

Perl’s file globbing uses the FreeBSD-style globbing, but it works mostly everywhere since Perl handles it internally through the File::Glob module. I’m working on the “Directory Operations” chapter for Learning Perl, 7th edition, where we cover glob. I’m trying to make the book more Windows friendly so I’ve been considering how this stuff translates.

I ran across Raymond Chen’s “How did wildcards work in MS-DOS?”. He lays out the steps for turning what we think of as a pattern (such as “*.txt”) into the CP/M-style pattern that MS-DOS used. He shows how to convert the glob pattern to primitive pattern. Continue reading “DOS pattern matching, in Perl”

Perl’s special not a numbers

Perl has some “numbers” that aren’t really numbers. Or, it has them if your underlying C library supports them.

The first, the “not a number”, is the string “NaN”, in any case. This isn’t a single value. The standard for floating-point numbers, IEEE 754. This value, which isn’t a number, returns itself in any mathematical operation. Continue reading “Perl’s special not a numbers”

A use for the scalar reverse (maybe)

The reverse operator, which turns a list end to front, has a scalar context too. It’s one of the examples I use in my Learning Perl classes to note that you can’t guess what something does in context. I’ve never had a decent example for a proper use, but flipping a string around to effectively scan from the right seems interesting. Continue reading “A use for the scalar reverse (maybe)”