Differences between revisions 1 and 2
Revision 1 as of 2002-04-02 22:49:24
Size: 616
Editor: anonymous
Comment: missing edit-log entry for this revision
Revision 2 as of 2002-05-28 11:53:10
Size: 935
Editor: SimonHuggins
Comment:
Deletions are marked like this. Additions are marked like this.
Line 9: Line 9:
----
Line 18: Line 16:
=== 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/' *
}}}


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


CategoryComputingTips

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