Hi all,

I'm using a guard object, and in simple cases where the guard is simply created and then left to it's devices, you get a useless "Useless" warning. Eg:

... my $guard = My::Guard->new(sub { $sth->finish }); ...

Yields the warning:

Useless use of private variable in void context at <snip> line 169. Of course I can suppress this warning with no warnings 'void', but I'm vaguely paranoid that in some circumstance or perl version, the variable might be optimised out of existence thus breaking the guard object use.

So I have two questions:

1. Any smart way to deal with the warning? Can I suppress it from within the guard package (which is by definition in a different scope to it's user)

2. Anyone know if the variable would ever be optimised away?

Update: My bad, it is not the simple assignment above which generates the warning, it's when I chain guards to preserve order. eg:

... my $guard1 = My::Guard->new(sub { $sth->finish }); ... some code which needs the protection of guard1 ... my $guard2 = My::Guard->new(sub { .. clear up something else ..; $guar +d1; }); ... some code which needs the protection of both guards, and the order + of resource clearing is important ...


In reply to useless Useless warning by aufflick

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.