aufflick has asked for the wisdom of the Perl Monks concerning the following question:
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 ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: useless Useless warning
by moritz (Cardinal) on Jun 24, 2008 at 08:06 UTC | |
by aufflick (Deacon) on Jun 25, 2008 at 01:45 UTC | |
by ikegami (Patriarch) on Jun 25, 2008 at 02:05 UTC | |
|
Re: useless Useless warning
by Anonymous Monk on Jun 24, 2008 at 09:23 UTC | |
by aufflick (Deacon) on Jun 25, 2008 at 01:51 UTC | |
|
Re: useless Useless warning
by aufflick (Deacon) on Jul 13, 2008 at 12:03 UTC |