FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Web Development
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
August 12, 2001

TPJ One Liners

(Page 4 of 6)
TPJ One-Liners - The Perl Journal


#31

perl -e  'print "Internet Time @",
  int (((time + 3600) % 86400)/86.4), "\n";'
Swatch's Internet Time, heralded as a revolutionary way
of measuring time independent of geography. See
http://www.swatch.com for details.

Anonymous
appeared in Issue 13


#32    A trick for indenting here strings

($definition = <<'FINIS') =~ s/^\s+//gm;
    The five varieties of camelids are the familliar
    camel, his friends the llama and the alpaca, and
    the rather less well-known guanaco and vicuna.
FINIS

Courtesy of The Perl Cookbook
appeared in Issue 13


#33

Efficiently finding the position of the first and last
occurrences of a substring in a string

$first = index($string, $substring);
$last = rindex($string, $substring);

appeared in Issue 13


#34

Some scalars that Perl defines for you:

$^O contains the name of your operating system.
$^T contains the time at which your program began.
$O contains the name of your program

appeared in Issue 13


#35    If Dr. Seuss were a Perl programmer

#!/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";

Courtesy of Kevin Meltzer
appeared in Issue 14


#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.

appeared in Issue 14


#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
appeared in Issue 14


#38

Replacing tabs with spaces

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

Courtesy of Abigail
appeared in Issue 14


#39

Printing all capitalized words

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

appeared in Issue 14




Previous Page | 1 | 2 | 3 | 4 | 5 | 6 Next Page
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK