Surprising output for the descending range ’01’..’-1′

[This is fixed in Perl v5.32]

The range operator has some interesting features to do more numbers, and one of them looks like it has some unintended special cases.

A couple of months ago, Hauke D reported some strange behavior with the range operator. Some of this is likely to be clarified in the v5.30 documentation but the odd cases remain. One part of this is useful and the others are probably surprising. Don’t depend on this feature for anything that’s important. Even though it acts like this, the undesigned feature may disappear.

Continue reading “Surprising output for the descending range ’01’..’-1′”

Powerful command-line options

Gabor has his listicle for 7 of the most useful Perl command line options, although it’s really five after giving separate items for the -v / -V and -e / -E pairs. The others are -p, -n, and -i. I have my own list that I’d like to share. You might not like my list; go through perlrun to find your own. There’s also the book Perl One-Liners.

Continue reading “Powerful command-line options”

Watch regexes with Regexp::Debugger

Wouldn’t it be great if books had embedded videos? That would make programming textbooks so much easier.

We have to give some hints about how regexes work in the first regex chapter in Learning Perl. It’s hard to describe something like greedy matching and backtracking with only words. It seems like it should be simple to describe, but you are probably like me: you think that because you already understand those concepts. Continue reading “Watch regexes with Regexp::Debugger”

The locale’s thousands separator

Perl can use the thousands separator appropriate for your locale, as well as the appropriate decimal separator. The Number::Format from CPAN can do all sorts of interesting localizations, but POSIX can do it.

I debated offering an example in Learning Perl (7th Edition), but POSIX‘s localeconv function returns a hash reference. And, although I’ve added an appendix covering experimental features, I didn’t want to go through enough Perl to explain slices and postfix dereferencing. Continue reading “The locale’s thousands separator”