Skip to Content
Perl One-Liners
book

Perl One-Liners

by Peteris Krumins
December 2013
Intermediate to advanced
168 pages
2h 49m
English
No Starch Press
Content preview from Perl One-Liners

Chapter 6. Text Conversion and Substitution

In this chapter, we’ll look at various one-liners that change, convert, and substitute text, including base64 encoding and decoding, URL escaping and unescaping, HTML escaping and unescaping, converting text case, and reversing lines. You’ll also get to know the y, tr, uc, lc, and reverse operators and string-escape sequences.

6.1 ROT13 a string

perl -le '$string = "bananas"; $string =~ y/A-Za-z/N-ZA-Mn-za-m/; print $string'

This one-liner uses the y operator (also known as the tr operator) to do ROT13. The operators y and tr perform string transliteration. Given y/search/replace/, the y operator transliterates all occurrences of the characters found in the search list with the characters in the corresponding ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl Best Practices

Perl Best Practices

Damian Conway
Perl Cookbook

Perl Cookbook

Tom Christiansen, Nathan Torkington
Minimal Perl

Minimal Perl

Tim Maher
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9781457185281Errata