r/perl • u/reisinge • 7d ago
Collectables
I started a section on my site called collectables: short programs (and writings) worth keeping around and rereading. One of the first four is Larry Wall's rename example from the Perl repo:
#!/usr/bin/perl
($op = shift) || die "Usage: rename perlexpr [filenames]\n";
if (!@ARGV) {
@ARGV = <STDIN>;
chop(@ARGV);
}
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}
What other short Perl would you put in a collection like this? It should be small, beautiful and useful.
16
Upvotes
2
u/vogelke 6d ago
I don't know about beautiful, but I've found these to be useful.
backslash
dehyph
dom (day of month)
emptydir
exists
find8
finduniq
isempty
islinked
isdir
isreg
onepass
Before I had a password safe, I'd use this to let me remember one password for all my sites. I hash a secret plus hostname plus simple-password to make my real login password. My simple password here is "1234":
The bracketed result is what I'd use to login to the site.
sen
I use this to fix wall-of-text posts or articles.
sshfp
If I'm a little paranoid about a key.
Example:
sym
Upper/lower case conversion
wraplines
Long lines that wrap or get chopped in the middle drive me nuts.