2024 π Daylatest newsbuy art
Poetry is just the evidence of life. If your life is burning well, poetry is just the ashLeonard Cohenburn somethingmore quotes
very clickable
data + munging

The Perl Journal

Volumes 1–6 (1996–2002)

Code tarballs available for issues 1–21.

I reformatted the CD-ROM contents. Some things may still be a little wonky — oh, why hello there <FONT> tag. Syntax highlighting is iffy. Please report any glaring issues.

The Perl Journal
#12
Winter 1998
vol 3
num 4
Just the FAQs: Coping with Scoping 3
Perl's two schemes for naming variables.
Perl Heresies 8
Not all conventional Perl wisdom is wise.
A Dynamic Navigation Bar with mod_perl 10
Navigation bar envy, sated with Apache and Perl.
Installing Perl and Perl/Tk on Win32
The trials and tribulations of a Unix user on Windows.
s/$text/speech $1/eg;
Kevin Lenzo
Perl News
What's new in the Perl community.
Bricolage: Data Compression
How to squeeze your data into the smallest possible space.
The man(1) of Descent
Generating your own parsers in Perl.
The Perl Quiz Show
For ten points, what magazine are you reading now?
The Perl Journal One Liners
(1998) The Perl Journal One Liners. The Perl Journal, vol 3(4), issue #12, Winter 1998.

The Perl Journal One Liners


TPJ One Liner #21

Picking random elements from an array:


srand;
$item = $array[rand @array];

TPJ One-liner #22

If you're trying to get Windows to generate a PostScript file,
but it wraps the file with PCL junk, you can remove it with this:


perl -ni -e "!$g&&s/^.*(%!.*)/$1/&&$g or print;last if /^%%
EOF/"

TPJ One-liner #23

In the movie Sphere, the commands that Harry typed to translate the message were taken from Tom Christiansen's FAQ:


$BSD = -f '/vmunix'; if ($BSD) {system "BIN
cbreak </dev/tty >/dev/tty 2>&1
sub set_break { # &setset_cbreak(1) or &set_cbreak(0)
      local($on) = $_[0];
	  local($sgttyb,@ary);
	  require 'sys/ioctl.ph';

Courtesy of Brendan O'Dea

TPJ One-liner #24

Seperate the header and body of a mail message into strings:


while (<>)  {
    $in_header =   1  ../^$/;
	$in_body   = /^$/ ..eof();

Courtesy of the Perl Cookbook

TPJ One-Liner #25

Simple numeric tests:

warn "has nondigits" if /\D/;
warn "not a natural number" unless /^\d+$/;
warn "not an integer" unless /^'?\d+$/;
warn "not an integer" unless /^[+']?\d+$/;
warn "not a decimal number" unless
             /^'?\d+\.?\d*$/; # rejects .2
warn "not a decimal number" unless
             /^'?(?:\d+(?:\.\d*)?|\.\d+)$/;
warn "not a C float" unless
            /^([+']?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/;

Courtesy of The Perl Cookbook.

TPJ One-Liner #26

Launching xterms with random colors. You might have to replace xterm with whatever command you use to launch a terminal window:


perl -e '$fg=rand 2**24; do { $bg = rand
2**24 } while (unpack("%32b*", pack "N",
($bg^$fg)&0xe0e0e0) < 8); ($fg, $bg) =
map { sprintf "#%06x", $_ } $fg, $bg;
exec("xterm", "-fg", $fg, "-bg", $bg);'
 

Courtesy of Tkil

TPJ One-Liner #27

Lop off the latter half of an array:

$#array /= 2;

Courtesy of The Perl Cookbook.

Martin Krzywinski | contact | Canada's Michael Smith Genome Sciences CentreBC Cancer Research CenterBC CancerPHSA
Google whack “vicissitudinal corporealization”
{ 10.9.234.152 }