home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / tutorial / eg / easy < prev    next >
Encoding:
Text File  |  1990-01-14  |  784 b   |  35 lines

  1. # one-liner perl examples.  
  2.  
  3. # output current version
  4. perl -v
  5.  
  6. # simplest perl program
  7. perl -e 'print "hello, world.\n";'
  8.  
  9. # useful at end of "find foo -print"
  10. perl -n -e 'chop;unlink;'
  11.  
  12. # add first and last columns (filter)
  13. perl -a -n -e 'print $F[0] + $F[$#F], "\n";'
  14.  
  15. # map to lower-case, swap first two fields if right kind
  16. perl -p -e 'tr/A-Z/a-z; s/(c[cp]u\d+) ([\d:]+)/$2 $1/;'
  17.  
  18. # in-place edit of *.c files changing all foo to bar
  19. perl -p -i -e 's/\bfoo\b/bar/g;' *.c
  20.  
  21. # as above but leave backup version in .bak files
  22. perl -p -i.bak -e 's/\bfoo\b/bar/g;' *.c
  23.  
  24. # run a script under the debugger
  25. perl -d myscript
  26.  
  27. # just get the debugger
  28. perl -d -e '0;'
  29.  
  30. # invoke the C preprocessor first.
  31. perl -P script
  32.  
  33. # which is the same as beginning a script this way:
  34. #!/usr/bin/perl -P
  35.