#31 Anonymous
#32 A trick for indenting here strings Courtesy of The Perl Cookbook
#33
Efficiently finding the position of the first and last
#34
$^O contains the name of your operating system.
#35 If Dr. Seuss were a Perl programmer Courtesy of Kevin Meltzer
#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.
#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
#38
Replacing tabs with spaces Courtesy of Abigail
#39
Printing all capitalized words
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.
appeared in Issue 13
($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
appeared in Issue 13
occurrences of a substring in a string
$first = index($string, $substring);
$last = rindex($string, $substring);
Some scalars that Perl defines for you:
$^T contains the time at which your program began.
$O contains the name of your program
#!/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";
appeared in Issue 14
appeared in Issue 14
perl -0011 -pi -e '/\011/&apm;&($_="$'")' filename
appeared in Issue 14
perl -ne 'push@w,/(\b[A-Z]\S*?\b)/g;END{print"@w"}' file