mirror of
https://github.com/php/presentations.git
synced 2026-03-24 23:52:18 +01:00
29 lines
827 B
XML
29 lines
827 B
XML
<slide title="Command Line Perl">
|
|
<image filename="onion.jpg" align="right" marginright="1.0em"/>
|
|
<blurb>
|
|
Perl is very good at one line programs to finish complicated
|
|
tasks:
|
|
</blurb>
|
|
<break lines="3"/>
|
|
<example fontsize="1.2em">
|
|
<![CDATA[# Taken from a message sent by Tom Christianson to
|
|
# comp.lang.perl.misc
|
|
|
|
## Reverse all the lines in a file, or set of files
|
|
perl -e 'print reverse <>' filename1, filename2, ...
|
|
|
|
## Increment all the numbers in a file by 1
|
|
perl i.tiny -pe 's/(\d+)/1 + $1/ge' filename1, filename2, ...
|
|
|
|
## Binary edit
|
|
perl -i.bak -pe 's/Mozilla/Slopoke/g' `which mozilla`
|
|
|
|
## Look for duplicate words
|
|
perl -0777 -ne 'print "$,: doubled $_\n" while /\b(\w+)\b\s+\b\1\b/gi' < filename
|
|
|
|
## In-place edit of *.c files changing all foo to bar
|
|
perl -p -i.bak -e 's/\bfoo\b/bar/g' *.c
|
|
]]>
|
|
</example>
|
|
</slide>
|