PREVIOUS  TABLE OF CONTENTS 

The Perl Journal One-Liners

TPJ One-Liner #35

If Dr. Seuss were a Perl programmer

Courtesy of Kevin Meltzer

#!/usr/bin/perl
# 
# Will give errors if run with -w, so don't use -w :)
# Tested on NT with AS (5.005), GS (5.004_02), 
# and Solaris 2.6 (5.004_04)

if ("a packet hits a pocket") {
    On: a;
    socket(ON, A ,PORT,"")
           && the bus is interrupted as a very-last-resort
           && the address of the memory makes your 
              floppy disk, abort;
		
} else {

    "The socket packet pocket has an";
    error: to-report;
} 

if ("your cursor finds a menu item") { 
    "followed by a dash"
            && "the double clicking icon";
    puts: your-items-in-the-trash
            && your data is corrupted cause the 
               index("doesn't", "hash");

} else {
   "Your situation is hopeless"
            && Your system's gonna crash;
} 

if ("the label on the cable") {
    On-the-table, at-your-house;
    Says_the; 
    sub network {"is connected to the button on your mouse"};
    BUT: Your-packets, want-to; 
    {/tunnel to another protocol/};
    that's: repeatedly-rejected; 
    {/by the printer/}; "down the hall"
            && "YOUR SCREEN is all distorted";
    {/by the side effects of Gauss/};
    so: "your icons", in-the-window;
    "are as wavy as a souse";

} else {
    YOU: "may as well reboot" && "go out with a !";
    CAUSE: /Sure as Im a poet/;
    THIS: suckers-gonna-hang;
}

print "Seuss as a tech writer - Kevin Meltzer\n"; 
	

TPJ One-liner #36

Neal Stephenson's latest novel, Cryptonomicon, includes a Perl cryptosystem code-named Pontifex. You can read about it at http://www.well.com/user/neal/cypherFAQ.html#12.

TPJ One-liner #37

Stripping the eighth bits from a string $s &= "\177" x length($s);
Given a string in $s, this one-liner turns all of the "funny" characters
(like à or Œ) into regular seven-bit ASCII characters.
It works by ANDing the bit representation of each character with 127,
which removes the eighth bit. That turns à into L and Œ into N, for instance.

Courtesy of Tom Christiansen

TPJ One-liner #38

Replacing tabs with spaces

perl -0011 -pi -e '/\011/&&($_="$'")' filename

Courtesy of Abigail

TPJ One-Liner #39

Printing all capitalized words

perl -ne 'push@w,/(\b[A-Z]\S*?\b)/g;END{print"@w"}' file


PREVIOUS  TABLE OF CONTENTS 
\n