CategoryComputingTips > PerlCompTips
Perl Tips
Oneliners
Use perl -le '... print ...' instead of perl -e '... print ... ,"\n";' to get newlines. See man perl for the gory details about -l
Use perl -i.bak with -pe something to modify text and a list of filenames for a safe way to try your perl on files e.g. perl -i.bak -pe 's/^bar/baz/' *
Documentation
perldoc is actually useful:
- perldoc -f function
- perldoc modulek
You can find module documentation for the latest versions on http://search.cpan.org/
rename
rename is bundled with perl and installed in all good perl installs
It's really useful as the syntax is
Usage: rename [-v] perlexpr [filenames]
So renaming multiple files according to a pattern becomes suddenly easy.
rename 'tr/A-Z/a-z/' * rename 's/\.foo$/.bar/' *