Celebrazio Net

Contact Us

Perl One-Liners

Feb., 2017

Quick Perl. No time to explain. Just try them.

perl -e 'use URI::Escape;
   $safe= uri_escape("http://www.celebrazio.net/contact.html");
   print $safe . "\n";'

perl -e 'print @INC:'  ## gives my included libraries 

perl -e 'use Data::Dumper; print Dumper(\%INC);'
        ## lots of other cool stuff too

perl -e 'print join("\n",glob("\/dir{1,3,5,7,9}\/filename{v1,v2}.html")) . "\n"'

perl -p -i.bak -e 's/foo/bar/g' original.txt  ## creates .bak as backup

## grep from file1 -> list to stdout
 perl -ne ' if (@m = m[(url_.{4,9}_string)]gs ){foreach my $a (@m) { print "$a\n"} ;}'

## random dice rolls
perl -e ' for ($i=0;$i<50;$i++) { print int(rand 6) +1 }; print "\n"'

## compare checksums
cksum file1 file2 | perl -ane '$x ||= $F[0]; warn if $x != $F[0]'

# print utf8
perl -e ' use Encode qw/decode/; $terms=`cat file.txt`; print decode("utf8", $terms) . "\n";'

"With a PC, I always felt limited by the software available. On Unix, I am limited only by my knowledge."
-- Peter J. Schoenster

1998-2017 Celebrazio.net