in reply to Re: Debugger actions: On which lines?
in thread Debugger actions: On which lines?

Aha! Adding back the shebang line gives the error. Taking it out and it performs as one would expect!

To be crystal try:

#!/usr/bin/perl -w use strict; use warnings; my $x = 3; my $y; for(1..3){ $y = $x;print "line 6 ---- x = $x -- y = $y\n"; $y++; print "line 7 ---- x = $x -- y = $y\n"; $x -= $y; print "line 8 ---- x = $x -- y = $y\n"; }

For me that has the error and...

use strict; use warnings; my $x = 3; my $y; for(1..3){ $y = $x;print "line 6 ---- x = $x -- y = $y\n"; $y++; print "line 7 ---- x = $x -- y = $y\n"; $x -= $y; print "line 8 ---- x = $x -- y = $y\n"; }

....does not

Replies are listed 'Best First'.
Re^3: Debugger actions: On which lines?
by 1nickt (Canon) on Aug 18, 2015 at 05:40 UTC

    It's not the shebang, it's the -w switch. Take out -w and only use use warnings instead and the error goes away because warnings is lexically scoped but -w is global. Using -w turned warnings on globally which is why your error came from the debugger code as it told you.

    I don't know why the action is executed on each line of the loop; I agree that docs indicate that it should be executed only on that line each time through the loop.

    Update: Realized the example code had both -w and use warnings.

    The way forward always starts with a minimal test.
      Declaring $y with a value fixed the issue for me and i didnt have to change anything. Just declare $y before the loop $y = 0;

        It doesn't "fix the issue for me". Did you run the script under the debugger all the way?

        Despite your results, using -w still turns warnings on globally, which is why the OP encountered the error with his code. See the demonstration below.

        Of course none of this answers his original question, i.e. why is the action executed on every line after it's first executed?

        [23:11][nick:~/monks]$ cat 1138950-2.pl #!/usr/bin/perl -w use strict; use warnings; my $x = 3; my $y = 0; for(1..3){ $y = $x; $y++; $x -= $y; } [23:11][nick:~/monks]$ perl -d 1138950-2.pl Loading DB routines from perl5db.pl version 1.49 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(1138950-2.pl:6): my $x = 3; DB<1> a 11 say $y + DB<2> n + main::(1138950-2.pl:7): my $y = 0; DB<2> + main::(1138950-2.pl:9): for(1..3){ DB<2> + main::(1138950-2.pl:10): $y = $x; DB<2> + main::(1138950-2.pl:11): $y++; 3 DB<2> + main::(1138950-2.pl:12): $x -= $y; 4 DB<2> + main::(1138950-2.pl:10): $y = $x; 4 DB<2> + main::(1138950-2.pl:11): $y++; -1 DB<2> + main::(1138950-2.pl:12): $x -= $y; 0 DB<2> + main::(1138950-2.pl:10): $y = $x; 0 DB<2> + main::(1138950-2.pl:11): $y++; -1 DB<2> + main::(1138950-2.pl:12): $x -= $y; 0 DB<2> + Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info. Use of uninitialized value $y in say at (eval 18)[/Users/nick/perl5/pe +rlbrew/perls/perl-5.22.0/lib/5.22.0/perl5db.pl:737] line 1. at (eval 18)[/Users/nick/perl5/perlbrew/perls/perl-5.22.0/lib/5.22.0/ +perl5db.pl:737] line 1. eval 'no strict; ($@, $!, $^E, $,, $/, $\\, $^W) = @DB::saved;pack +age main; say $y; ' called at /Users/nick/perl5/perlbrew/perls/perl-5.22.0/lib/5.22.0/pe +rl5db.pl line 737 DB::eval called at /Users/nick/perl5/perlbrew/perls/perl-5.22.0/li +b/5.22.0/perl5db.pl line 2681 DB::DB called at /Users/nick/perl5/perlbrew/perls/perl-5.22.0/lib/ +5.22.0/perl5db.pl line 10345 DB::fake::at_exit() called at /Users/nick/perl5/perlbrew/perls/per +l-5.22.0/lib/5.22.0/perl5db.pl line 9916 DB::END() called at (eval 18)[/Users/nick/perl5/perlbrew/perls/per +l-5.22.0/lib/5.22.0/perl5db.pl:737] line 0 eval {...} called at (eval 18)[/Users/nick/perl5/perlbrew/perls/pe +rl-5.22.0/lib/5.22.0/perl5db.pl:737] line 0 DB<2>

        Compare with no -w switch:

        [23:15][nick:~/monks]$ cat 1138950-3.pl #!/usr/bin/perl use strict; use warnings; my $x = 3; my $y = 0; for(1..3){ $y = $x; $y++; $x -= $y; } [23:15][nick:~/monks]$ perl -d 1138950-3.pl Loading DB routines from perl5db.pl version 1.49 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(1138950-3.pl:6): my $x = 3; DB<1> a 11 say $y + DB<2> n + main::(1138950-3.pl:7): my $y = 0; DB<2> + main::(1138950-3.pl:9): for(1..3){ DB<2> + main::(1138950-3.pl:10): $y = $x; DB<2> + main::(1138950-3.pl:11): $y++; 3 DB<2> + main::(1138950-3.pl:12): $x -= $y; 4 DB<2> + main::(1138950-3.pl:10): $y = $x; 4 DB<2> + main::(1138950-3.pl:11): $y++; -1 DB<2> + main::(1138950-3.pl:12): $x -= $y; 0 DB<2> + main::(1138950-3.pl:10): $y = $x; 0 DB<2> + main::(1138950-3.pl:11): $y++; -1 DB<2> + main::(1138950-3.pl:12): $x -= $y; 0 DB<2> + Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info. DB<2> + Use 'q' to quit or 'R' to restart. 'h q' for details.
        The way forward always starts with a minimal test.
Re^3: Debugger actions: On which lines?
by james28909 (Deacon) on Aug 18, 2015 at 05:32 UTC
    It works with or without the shebang for me, go figure... I have windows 10 64bit and active-state perl 5.16.3 32bit. I think you should declare $y before the loop though like my $y = 0; that would probably get rid of your errors.

      Hmmm.... It has never worked for me. I always thought I was doing some thing wrong but I never needed it. I needed it today....

      My Perl

      /tmp$ perl -v This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-li +nux-gnu-thread-multi (with 41 registered patches, see perl -V for more detail) [snip]

      My OS...

      /tmp$ cat /etc/issue Ubuntu 14.04.3 LTS \n \l