in reply to Debugger actions: On which lines?

Not trying to go off topic, but isnt that code slightly redundant? after the first loop the output will always be the same. But back to the question. I do not get any errors using strict or warnings, or in the debugger.
#!/usr/bin/perl -w use strict; use warnings; my $x = 3; my $y = 0; for(1..3){ $y = $x; print "line 1 ---- x = $x -- y = $y\n"; $y++; print "line 2 ---- x = $x -- y = $y\n"; $x -= $y; print "line 3 ---- x = $x -- y = $y\n"; }

EDIT: Updated code

Replies are listed 'Best First'.
Re^2: Debugger actions: On which lines?
by worik (Sexton) on Aug 18, 2015 at 05:29 UTC

    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

      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 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