Checking that a value is between two others involves two comparisons, and so far in Perl that’s meant that you’ve had to type one of the values more than once. That gets simpler in v5.32 with chained comparisons. This would make Perl one of the few languages that support the feature. So far its implemented in v5.31.10 and until v5.32 is actually released, it isn’t a real feature.
Continuing its quest to clean up long deprecated features, v5.28 takes care of another feature deprecated since v5.0. You can no longer neglect to specify a heredoc separator. This was a warning in v5.26 and is now fatal. You probably weren’t doing this anyway (I’ve never seen it in the wild), but it’s nice to know the edge cases are disappearing.
Perl v5.28 will have better deprecation warnings. Most of this I picked up from the lightning talk that Abigail gave at The Perl Conference. Continue reading “Deprecation warnings now tell you when the features will disappear”
You can specify literal hexadecimal floating-point numbers in v5.22, just as you can in C99, Java, Ruby, and other languages do. Perl, which uses doubles to store floating-point numbers, can represent a limited set of values. Up to now, you’ve had to specify those floating point numbers in decimal, hoping that a double could exactly represent that number. That hope, sometimes unfounded, is the basis for the common newbie question about floating point errors. Continue reading “Perl v5.22 adds hexadecimal floating point literals”
Perl v5.20 adds the “Key/Value Slice”, which extracts multiple keys and their corresponding values from a container (hash or array). It uses the
%, which is new, legal syntax for a variable name with subscripts after it: Continue reading “Perl 5.20 introduces “Key/Value Slices””
Perl’s powerful string manipulation tools include case-shifting operators that change the parts of a double-quoted string. There are many other things that happen in a double-quoted string too, so you need to know where these operators fit in with each other. Continue reading “Understand the order of operations in double quoted contexts”
Perl defines two internal pseudo-signals that you can trap. There’s one for die, which I covered in Override die with END or CORE::GLOBAL::die and eventually told you not to use. There’s also one for warn that’s quite safe to use when you need to intercept warnings. Continue reading “Intercept warnings with a __WARN__ handler”
$_ was removed in v5.24]
Perl 5.10 introduced the
given-when feature, a fancier version of the C
switch feature. However, it was poorly designed and tested and depended on two other dubious features, the lexical
$_ and smart-matching. Parts of this feature are salvageable, but you should avoid the literal
given (and probably the lexical
$_ and the smart matching, but I’ll skip those for this Item). Continue reading “Use for() instead of given()”
Perl will autovivify complex data structures when you use them as if they already exist. This feature saves you a lot of annoying work defining structures that you intend to use. However, this also means that Perl might create data structures that you don’t intend to use in code that isn’t just assigning values. Continue reading “Understand autovivification”
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”