Mapping..... (Was Stonehenge)
Brent Fulgham
brent.fulgham at xpsystems.com
Wed Aug 30 16:02:59 CDT 2000
In fact ... all this talk yesterday of 'maps' was coming back to me this
morning
while I tried to get Damian Conway's Coy.pm module to work. There were
several
routines like the following:
my $foo = join "|", map { chop; $_; }
(
"anathema", "bema", "carcinoma", "charisma", "diploma",
"dogma", "drama", "edema", "enema", "enigma", "lemma",
"lymphoma", "magma", "melisma", "miasma", "oedema",
"sarcoma", "schema", "soma", "stigma", "stoma", "trauma",
"gumma", "pragma",
);
I must admit, I wasn't exactly sure what this did. I fired it off in a test
program to see what $foo is filled with:
anathem|bem|carcinom|charism|...etc...
So it basically modifies the unnamed list in place, to yield a list of words
with the last character missing. The funny 'map' statement is a functional
way of doing the following:
my @list = ("anathema", "bema", ... ,"gumma", "pragma");
my $foo;
foreach $word (@list)
{
chop $word;
$foo .= $word
$foo .= "|"
}
(except better because it doesn't stick an extra "|" at the end).
Anyway, Perl 5.6 apparently changes things a bit so you can't modify an
unnamed
construct list (which is basically a constant) in-place. So the fix is to
say:
my $bar = join "|", map { my $val = $_; chop $val; $val}
(
"anathema", "bema", "carcinoma", "charisma", "diploma",
"dogma", "drama", "edema", "enema", "enigma", "lemma",
"lymphoma", "magma", "melisma", "miasma", "oedema",
"sarcoma", "schema", "soma", "stigma", "stoma", "trauma",
"gumma", "pragma",
);
Which just introduces a new temporary variable. Is it less efficient? Who
knows.
I sent a funny e-mail to Damian about the fix:
--------------------------------
Tension mounting. Stress.
Broken Coy is bad karma!
Where can I find peace?
It seems that Perl five
point six broke your Coy module.
Attached is a patch.
You will, no doubt, need
to make it harmonious
with the rest of Coy.
Water falls on a rock.
A small gift from neophyte
to the great teacher.
---------------------------------
It was a great honor to get an e-mail back from him
later this same day:
When the student can
patch the teacher's broken code,
who is the master?
Many thanks, grasshopper.
Damian
More information about the Thousand-oaks-pm
mailing list