in reply to Re^5: Warnings on unused variables?
in thread Warnings on unused variables?

Just tested, using the same code I used earlier, substituting in each new eval block one at a time without using exit(), i.e.:

#!/usr/bin/perl use warnings; use warnings::unused; use strict; my $foo = 42; my $bar = 43; eval '$'.'foo++';

Result for eval '$'.'foo++':

Unused variable my $bar at ./warntest.pl line 8.

Result for eval 'print q{$foo++}':

Unused variable my $foo at ./warntest.pl line 7. Unused variable my $bar at ./warntest.pl line 8. $foo++%

(the % is inverted on my terminal, and is a lack-of-newline marker)

Result for eval '$cond ? $foo : $bar': (blank).

Double-checking that my original example didn't cause a funny result because I wrapped it in exit, I checked eval q[$foo++];

Unused variable my $bar at ./warntest.pl line 8.

So it looks like it does what you'd expect, other than the first example, and more or less exactly what I want.

Replies are listed 'Best First'.
Re^7: Warnings on unused variables?
by ikegami (Patriarch) on Sep 28, 2008 at 00:58 UTC
    Turns out it was easy to install on my Windows machine. It stops behaving "properly" when the eval is in a function. Warnings for both $foo and $bar are emitted as soon as the function is compiled.
    #!/usr/bin/perl use warnings; use warnings::unused; use strict; BEGIN { print("1\n"); } sub foo { my $foo = 42; my $bar = 43; eval '$foo++'; print("4\n"); <>; # <-- Segfaults when this is executed. } # <-- Warns when this is compiled BEGIN { print("2\n"); } print("3\n"); foo(); print("5\n"); <>;

      ... very interesting. On my Debian box, I get a different result, with no segfault.

      1 Unused variable my $foo at ./warntest.pl line 9. Unused variable my $bar at ./warntest.pl line 10. 2 3 4 5

      The blank link after 4 and 5 indicate spots where I pressed return to get it to continue. Did it pass all of the tests in 'make test' in your build environment? My current Windows test box is running ActiveState, so I can't get it to build to test it myself there. One of these days after my current project is finished I plan to rip it out and try Strawberry again.

        I get a different result, with no segfault

        That's the same result, with no segfault

        My current Windows test box is running ActiveState

        Same here.

        Did it pass all of the tests in 'make test' in your build environment?

        Yes:

        Running make test Microsoft (R) Program Maintenance Utility Version 6.00.8168.0 Copyright (C) Microsoft Corp 1988-1998. All rights reserved. C:\Progs\perl588\bin\perl.exe "-MExtUtils::Command::MM" "-e" " +test_harness(0, 'inc', 'blib\lib', 'blib\arch')" t/*.t t/00_load............1/1 # Testing warnings::unused 0.01 t/00_load............ok t/01_unused..........ok t/02_used............ok t/03_in_mod..........ok t/99_pod-coverage....ok t/99_pod.............ok All tests successful. Files=6, Tests=20, 2 wallclock secs ( 0.11 usr + 0.05 sys = 0.16 CP +U) Result: PASS GFUJI/warnings-unused-0.01.tar.gz nmake test -- OK cpan[2]>
Re^7: Warnings on unused variables?
by ikegami (Patriarch) on Sep 28, 2008 at 00:52 UTC
    Interesting! It must produces when the program exits. The existing warning for package variables occurs at compile-time.