<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:

perl -MCoy -e "wibble()"

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 $PL_sb_C_en_ina = join "|", map { my $a = $_; chop $a; chop $a; $a +} ( "stamen", "foramen", "lumen", );
My second fix included changing the source data format:
my $PL_sb_C_en_ina = join "|", map { chop; chop; $_ } split /\s+/, q(stamen foramen lumen);
My third included a gratuitous use of a regex:
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.


In reply to Modification of a read-only value attempted: MTOWTFI by grantm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.