http://www.catonmat.net/blog/perl-one-liners-explained-part-five/
65. URL-escape a string.
perl -MURI::Escape -le 'print uri_escape($string)'
You’ll need to install the URI::Escape module as it doesn’t come with Perl. The module exports two functions - uri_escape and uri_unescape. The first one does URL-escaping (sometimes also referred to as URL encoding), and the other does URL-unescaping (URL decoding).
66. URL-unescape a string.
perl -MURI::Escape -le 'print uri_unescape($string)'
This one-liner uses the uri_unescape function from URI::Escape module to do URL-unescaping.
67. HTML-encode a string.
perl -MHTML::Entities -le 'print encode_entities($string)'
This one-liner uses the encode_entities function from HTML::Entities module. This function encodes HTML entities. For example, < and > get turned into < and >.
68. HTML-decode a string.
perl -MHTML::Entities -le 'print decode_entities($string)'
This one-liner uses the decode_entities function from HTML::Entities module.
More links
============
- Famous Sed One-Liners Explained, Part I: File Spacing, Numbering and Text Conversion and Substitution
- Famous Perl One-Liners Explained, Part IV: String and Array Creation
- Famous Perl One-Liners Explained, Part III: Calculations
- Famous Perl One-Liners Explained, Part II: Line Numbering
- Famous Perl One-Liners Explained, Part I: File Spacing
- Famous Awk One-Liners Explained, Part II: Text Conversion and Substitution
- Update on Famous Awk One-Liners Explained: String and Array Creation
- Famous Sed One-Liners Explained, Part III: Selective Deletion of Certain Lines and Special Applications
- Famous Awk One-Liners Explained, Part III: Selective Printing and Deleting of Certain Lines
- Famous Sed One-Liners Explained, Part II: Selective Printing of Certain Lines
No comments:
Post a Comment