home *** CD-ROM | disk | FTP | other *** search
- # one-liner perl examples.
-
- # output current version
- perl -v
-
- # simplest perl program
- perl -e 'print "hello, world.\n";'
-
- # useful at end of "find foo -print"
- perl -n -e 'chop;unlink;'
-
- # add first and last columns (filter)
- perl -a -n -e 'print $F[0] + $F[$#F], "\n";'
-
- # map to lower-case, swap first two fields if right kind
- perl -p -e 'tr/A-Z/a-z; s/(c[cp]u\d+) ([\d:]+)/$2 $1/;'
-
- # in-place edit of *.c files changing all foo to bar
- perl -p -i -e 's/\bfoo\b/bar/g;' *.c
-
- # as above but leave backup version in .bak files
- perl -p -i.bak -e 's/\bfoo\b/bar/g;' *.c
-
- # run a script under the debugger
- perl -d myscript
-
- # just get the debugger
- perl -d -e '0;'
-
- # invoke the C preprocessor first.
- perl -P script
-
- # which is the same as beginning a script this way:
- #!/usr/bin/perl -P
-