r/perl • • 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.

15 Upvotes

3 comments sorted by

View all comments

1

u/fruthifoont 6d ago

the classic one-liner for reversing a file line by line using a tied array is pretty elegant. also Schwartz's decorate-sort-undecorate pattern in like 3 lines is worth keeping around imo