In a recent article at www.perl.com, I showed some code that looked like this:
"nosehair" while s/(.{1,3})\*/*,$1/;
The code was a joke, and I was rather irritated when people write to me to 'correct' it.

Today I got mail from someone who complained that the string "nosehair" generated a 'Useless use of constant in void context' warning under -w, and suggested that I change it to 1 instead. I thought this was a little silly, because you should not have to turn on -w to know that "nosehair" is a bad idea.

One of the big problems with -w is that some people have it wired to a toggle switch and when they turn on -w they disable their brains at the same time.

Anyway, I suggested that if this guy's only problem with "nosehair" was that it generated a warning under -w, he could make the warning go away with the following change:

"ignore my nose hairs, please" while s/(.{1,3})\*/*,$1/;

That's the obfuscation. The puzzle is, why does changing the string make the warning go away?

I will reveal the answer in a couple of days; or you can find it on page 321 of the pink camel book.

(Please don't post spoilers, especially if you were hanging around when I explained it in the chatbox this afternoon. Also if you are Randal, then we already know that you know the answer, since you are an author of the pink camel book.)


In reply to How to make warnings disappear by Dominus

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.