There's been only one followup thus far in clpmisc (that I can see):

There have been other two:

Jürgen Exner

Useful? Yes.
Easy to implement? No.

Example:

my ($x, $y) = (1,2); if (<some complex condition depending on the environment>) { call_my_sub($x) } else { call_my_sub($y) }

In this example either $x or $y remains unused. However a static analysis at compile time cannot detect this.

And neither can a dyamic analysis during runtime because that complex condition may evaluate to false only in an odd one-in-a-million situation.

Jim Gibson

Useful? Yes.
Easy to implement? No.

Example:

my ($x, $y) = (1,2); if (<some complex condition depending on the environment>) { call_my_sub($x) } else { call_my_sub($y) }

In this example either $x or $y remains unused. However a static analysis at compile time cannot detect this.

But both $x and $y appear in two separate instances within their scope. Contrast that with:

my ($x, $y) = (1,2); if (<condition>) { call_my_sub($x) } else { call_my_sub($z) }

$y and $z both only appear once, so it looks like there has been a typo. That is the type of error that could be caught with an analysis of lexical variables.

And neither can a dyamic analysis during runtime because that complex condition may evaluate to false only in an odd one-in-a-million situation.

A dynamic analysis is not needed.


Update: one last entry...

Peter J. Holzer

On 2007-09-06 18:58, Jürgen Exner wrote:

Peter J. Holzer wrote:

It would be nice if perl could warn about lexical variables which are never used in their scope after their initialization. Does anybody else find this useful, and if so, is there a reason (besides "life is short") why it hasn't been implemented?

Useful? Yes.
Easy to implement? No.

I don't think it would be particularly hard to implement. That's a rather common feature in compilers which generate machine code (IIRC it's a byproduct of register allocation). But I don't know how expensive it is - since perl compiles the source code every time it is run, we want to avoid algorithms which can potentially take a long time.

Example:

my ($x, $y) = (1,2); if (<some complex condition depending on the environment>) { call_my_sub($x) } else { call_my_sub($y) }

In this example either $x or $y remains unused.

In any particular run, yes. But both branches are possible, so you can eliminate neither $x nor $y. So that code is ok, although it would probably be cleaner to rearrange it as:

if (<some complex condition depending on the environment>) { my $x = 1; call_my_sub($x) } else { my $y = 2; call_my_sub($y) }

In reply to Re^2: Warning about unused lexical variables by blazar
in thread Warning about unused lexical variables by blazar

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.