Copy instead of renaming to preserve hard links

Yesterday I posted about not overwriting a file until you knew you had completely and correctly stored its data. Part of that was about data security and another part was completeness for other consumers. I used a temporary file and rename to move the new file into place. That’s not the entire story though.

Continue reading “Copy instead of renaming to preserve hard links”

Use a temporary file instead of clobbering data

How do you replace the the contents of a file? This is something I’ve been thinking quite a bit about because we often get away with bad practices, and it’s completely within the scope of Learning Perl to know how to do this. It might make a good edition to the next edition of the book.

Someone on Stackoverflow asked if it was okay to read from a file then write back to the same file. In this case, completely read the file and once done, write to the same filename. Most of the answers deal with the mechanics and miss the wisdom of that design.
That’s a problem with tutorial books too: there are only so many pages.

Continue reading “Use a temporary file instead of clobbering data”

Starting to think about an 8th Edition

I’ve finished some other book projects (notably Learning Perl 6 and Mojolicious Web
Clients
), and it’s time to think about what I need to do to
refresh my other books.

The 7th Edition covers up to v5.24 and now we’re on to v5.30 (with
v5.32 soon). I track interesting new features at The Effective
Perler
.

Some notable things to include:

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”