Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: Warnings on unused variables?

by ikegami (Patriarch)
on Sep 27, 2008 at 23:02 UTC ( [id://714077]=note: print w/replies, xml ) Need Help??


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

In to the other class of examples, I just tested that #1 in fact does use $foo++, and warnings::unused handles it properly:

That's odd.
Does eval '$'.'foo++' issue a warning for $foo? (It shouldn't)
Does eval 'print q{$foo++}' issue a warning for $foo? (It should)
Does eval '$cond ? $foo : $bar' issue a warning for $foo and $bar? (It shouldn't)

Replies are listed 'Best First'.
Re^6: Warnings on unused variables?
by AZed (Monk) on Sep 28, 2008 at 00:46 UTC

    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++';
      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.

      Interesting! It must produces when the program exits. The existing warning for package variables occurs at compile-time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://714077]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-25 17:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found