<rambling_intro>
A workmate directed me at
the semantic web in haiku. This in turn put me in mind of TheDamian's Coy.pm which intercepts Perl's error messages and translates them into haiku. So after a quick perl -MCPAN -e "install 'Coy'" I attempted to induce an error with this one-liner:
Instead of a gentle soothing stanza, I was greeted with:
Modification of a read-only value attempted at /usr/lib/perl5/site_per +l/5.6.1/Lingua/EN/Inflect.pm line 168. Compilation failed in require at /usr/lib/perl5/site_perl/5.6.1/Coy.pm + line 19. BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.6.1/Co +y.pm line 19. Compilation failed in require. BEGIN failed--compilation aborted.
Not quite the effect I was going for :-(
</rambling_intro>
Anyway, to get to the point ("at last!" I hear you say), I dived into Lingua/EN/Inflect.pm and at line 168, found this code...
my $PL_sb_C_en_ina = join "|", map { chop; chop; $_; } ( "stamen", "foramen", "lumen", );
Now clearly this is a bug - the values passed to map are constants and since map aliases $_ to each value in turn, chop does attempt to modify a constant. It's also a bug that Damian has fixed already (all I had to do was install the latest Lingua::EN::Inflect). But this being Perl, there's "More Than One Way To Fix It". My first fix was to introduce an intermediate variable:
My second fix included changing the source data format:my $PL_sb_C_en_ina = join "|", map { my $a = $_; chop $a; chop $a; $a +} ( "stamen", "foramen", "lumen", );
My third included a gratuitous use of a regex:my $PL_sb_C_en_ina = join "|", map { chop; chop; $_ } split /\s+/, q(stamen foramen lumen);
my $PL_sb_C_en_ina = join "|", map { /^(.*)..$/ && $1 } split /\s+/, q(stamen foramen lumen);
Without peeking at Damian's code (in the latest version of Lingua::EN::Inflect) how would you fix it?
Update: fixed typo in first fix as per abell's note below.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Modification of a read-only value attempted: MTOWTFI
by jsprat (Curate) on Oct 14, 2002 at 22:37 UTC | |
|
Re: Modification of a read-only value attempted: MTOWTFI
by abell (Chaplain) on Oct 15, 2002 at 11:07 UTC | |
by BrowserUk (Patriarch) on Oct 15, 2002 at 11:14 UTC | |
by grantm (Parson) on Oct 15, 2002 at 20:30 UTC | |
|
Re: Modification of a read-only value attempted: MTOWTFI
by Ovid (Cardinal) on Oct 14, 2002 at 23:10 UTC | |
|
Re: Modification of a read-only value attempted: MTOWTFI
by Zaxo (Archbishop) on Oct 15, 2002 at 02:02 UTC | |
|
(tye)Re: Modification of a read-only value attempted: MTOWTFI
by tye (Sage) on Oct 14, 2002 at 22:52 UTC | |
|
Re: Modification of a read-only value attempted: MTOWTFI
by Aristotle (Chancellor) on Oct 14, 2002 at 23:49 UTC |