Command line Perl scripts for various purposes, such as HTML processing. Many of the examples work on STDIN.
# Check whether Perl module is installed
perldoc modulename
# Print paths where Perl looks for modules
perl -e 'print join "\n", @INC'
# Search and replace globally, ignore case
perl -i.bak -pe 's|searchstring|replacement|gi' infile
# Lower case all letters of input
perl -pe 's/([A-Z])/lc $1/ge' infile
# Encode STDIN with HTML entities
perl -MHTML::Entities -pe 'encode_entities($_)' infile
# Encode specified characters from STDIN with HTML entities
perl -MHTML::Entities -pe 'encode_entities($_, "\200-\377")' infile
# Decode STDIN with HTML entities
perl -MHTML::Entities -pe 'decode_entities($_)' infile
# Strip one line comments and blank lines from scripts
perl -pe 's%\s*(?:#[^!]|//).*|^\s*$%%s;' infile
# Using module subroutines that are not exported by default
perl -MCGI=:standard -e 'print start_html, end_html'
# Path to Perl's copy of the Unicode character database:
perl -MConfig -le 'print "$Config{privlib}/unicore/NamesList.txt"'
# Learn more about Perl's command line options
perldoc perlrun
Post new comment