Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2002-04-02 22:49:24
Size: 616
Editor: anonymous
Comment: missing edit-log entry for this revision
Revision 4 as of 2008-02-19 15:39:14
Size: 942
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
CategoryComputingTips > PerlCompTips
Line 8: Line 10:

----
Line 18: Line 18:
----
CategoryComputingTips
=== 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/' *
}}}

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/' *

TheEarthWiki: PerlCompTips (last edited 2008-02-19 15:39:14 by localhost)