Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 527 forks source link

perl -d treats $array[0..3] differently than non-debugger #1907

Closed p5pRT closed 18 years ago

p5pRT commented 24 years ago

Migrated from rt.perl.org#3177 (status was 'resolved')

Searchable as RT3177$

p5pRT commented 24 years ago

From jeffp@crusoe.net

This is with perl5.005_02\, by the way...

jeffp@​friday [11​:05pm] ~ #543> perl -de0

Loading DB routines from perl5db.pl version 1.0401 Emacs support available.

Enter h or `h h' for help.

main​::(-e​:1)​: 0   DB\<1> @​a = qw( A B C );

  DB\<2> x $a[0..3]\, $a[1..3] 0 'B' 1 'A'

perl -le '@​a = qw( A B C ); print $a[0..3]\, $a[1..3];' a a

Could someone explain this? :( Hmm... perhaps $. is defined in the debugger..........

p5pRT commented 24 years ago

From @tamias

On Thu\, Apr 27\, 2000 at 11​:07​:15PM -0400\, Jeff Pinyan wrote​:

This is with perl5.005_02\, by the way...

jeffp@​friday [11​:05pm] ~ #543> perl -de0

Loading DB routines from perl5db.pl version 1.0401 Emacs support available.

Enter h or `h h' for help.

main​::(-e​:1)​: 0 DB\<1> @​a = qw( A B C );

DB\<2> x $a[0..3]\, $a[1..3] 0 'B' 1 'A'

In 5.005_3\, I only get that result with​:

% perl -de 'BEGIN{@​a = qw( A B C )} 1' [...] main​::(-e​:1)​: BEGIN{@​a = qw(A B C)} 1   DB\<1> x $a[0..3]\, $a[1..3] 0 'A' 1 'B'

perl -le '@​a = qw( A B C ); print $a[0..3]\, $a[1..3];' a a

Or\, if you're being picky​:

AA

:)

Could someone explain this? :( Hmm... perhaps $. is defined in the debugger..........

Yes\, and the most recently read file handle is STDIN. This quirk of the debuger can be very frustrating at times.

Ronald

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

On Apr 27\, Ronald J Kimball said​:

In 5.005_3\, I only get that result with​:

% perl -de 'BEGIN{@​a = qw( A B C )} 1' [...] main​::(-e​:1)​: BEGIN{@​a = qw(A B C)} 1 DB\<1> x $a[0..3]\, $a[1..3] 0 'A' 1 'B'

Um\, does the BEGIN have anything special to do with it?

perl -le '@​a = qw( A B C ); print $a[0..3]\, $a[1..3];' a a

AA

Err\, yeah. I knew the output\, so it just follows logically that I write it instead of copy and paste it\, and that I write it INCORRECTLY.

  $brain |= TURN_ON;

Could someone explain this? :( Hmm... perhaps $. is defined in the debugger..........

Yes\, and the most recently read file handle is STDIN. This quirk of the debuger can be very frustrating at times.

Indeed it is -- I just found it out now. How annoying that can be.

p5pRT commented 24 years ago

From @tamias

On Thu\, Apr 27\, 2000 at 11​:16​:38PM -0400\, Jeff Pinyan wrote​:

On Apr 27\, Ronald J Kimball said​:

In 5.005_3\, I only get that result with​:

% perl -de 'BEGIN{@​a = qw( A B C )} 1' [...] main​::(-e​:1)​: BEGIN{@​a = qw(A B C)} 1 DB\<1> x $a[0..3]\, $a[1..3] 0 'A' 1 'B'

Um\, does the BEGIN have anything special to do with it?

No\, it's just that the first command needs to be C\<x $a[0..3]\, $a[1..3]> because that's when $. == 1. I don't know why you got 'B' after the second command.

Ronald

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

On Apr 27\, Ronald J Kimball said​:

No\, it's just that the first command needs to be C\<x $a[0..3]\, $a[1..3]> because that's when $. == 1. I don't know why you got 'B' after the second command.

jeffp@​friday [11​:21pm] ~ #551> perl -de0

Loading DB routines from perl5db.pl version 1.0401 Emacs support available.

Enter h or `h h' for help.

print $.main​::(-e​:1)​: 0   DB\<1> print $. 0   DB\<2> print $. 0   DB\<3> print $. 0

p5pRT commented 24 years ago

From @tamias

On Thu\, Apr 27\, 2000 at 11​:22​:08PM -0400\, Jeff Pinyan wrote​:

jeffp@​friday [11​:21pm] ~ #551> perl -de0

Loading DB routines from perl5db.pl version 1.0401 Emacs support available.

Enter h or `h h' for help.

print $.main​::(-e​:1)​: 0 DB\<1> print $. 0 DB\<2> print $. 0 DB\<3> print $. 0

% perl -de 0

Loading DB routines from perl5db.pl version 1.0402 Emacs support available.

Enter h or `h h' for help.

main​::(-e​:1)​: 0   DB\<1> print $. 1   DB\<2> print $. 2   DB\<3> print $. 3

(perl5.005_03)

I would say "time to upgrade"\, but I don't know that this is a significant difference. :)

Anyway\, I don't have access to v5.6.0 right now\, so I can't check what it does there.

Ronald

p5pRT commented 24 years ago

From @simoncozens

Anyway\, I don't have access to v5.6.0 right now\, so I can't check what it does there.

main​::(-e​:1)​: 42   DB\<1> print $. 1   DB\<2> print $. 2   DB\<3> print $. 3

__END__


The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review\, retransmission\, dissemination or other use of\, or taking of any action in reliance upon\, this information by persons or entities other than the intended recipient is prohibited. If you received this in error\, please contact the sender and delete the material from any computer.

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

"Ronald" == Ronald J Kimball \rjk@&#8203;linguist\.dartmouth\.edu writes​:   Ronald> Anyway\, I don't have access to v5.6.0 right now\, so I   Ronald> can't check what it does there.

rabbit% perl5.6.0 -de 0 Default die handler restored.

Loading DB routines from perl5db.pl version 1.07 Editor support available.

Enter h or `h h' for help\, or `man perldebug' for more help.

main​::(-e​:1)​: 0   DB\<1> print $.

  DB\<2> print $. 0   DB\<3> print $. 0   DB\<4> print $. 0   DB\<5> print $. 0

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

Anyway\, I don't have access to v5.6.0 right now\, so I can't check what it does there.

main​::(-e​:1)​: 42 DB\<1> print $. 1 DB\<2> print $. 2

Ok\, so I assume perl5db.pl is a different version (> 1.0401).

Does this new version have the correct documentation in the following comment?

  # The scalar ${'_\<'.$filename} contains "_\<$filename".

That should read

  # The scalar ${'_\<'.$filename} contains "$filename".

or perhaps

  # The scalar ${'_\<'.$filename} contains $filename.

But I'd go with the first\, for continuity reasons. Not having 5.005_03 or 5.6\, I'd not feel safe in submitting a patch.

p5pRT commented 24 years ago

From @simoncozens

Ok\, so I assume perl5db.pl is a different version (> 1.0401).

Yeah\, this is 1.07

Does this new version have the correct documentation in the following comment?

# The scalar ${'_\<'.$filename} contains "_\<$filename". That should read # The scalar ${'_\<'.$filename} contains "$filename".

Inline Patch ```diff --- lib/perl5db.pl~ Fri Apr 28 12:55:46 2000 +++ lib/perl5db.pl Fri Apr 28 12:56:00 2000 @@ -34,7 +34,7 @@ # interpreter, though the values used by perl5db.pl have the form # "$break_condition\0$action". Values are magical in numeric context. # -# The scalar ${'_<'.$filename} contains "_<$filename". +# The scalar ${'_<'.$filename} contains "$filename". # # Note that no subroutine call is possible until &DB::sub is defined # (for subroutines defined outside of the package DB). In fact the same is ```

END


The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review\, retransmission\, dissemination or other use of\, or taking of any action in reliance upon\, this information by persons or entities other than the intended recipient is prohibited. If you received this in error\, please contact the sender and delete the material from any computer.

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

Stephen Zander \gibreel@&#8203;pobox\.com wrote

"Ronald" == Ronald J Kimball \rjk@&#8203;linguist\.dartmouth\.edu writes​: Ronald> Anyway\, I don't have access to v5.6.0 right now\, so I Ronald> can't check what it does there.

rabbit% perl5.6.0 -de 0 Default die handler restored.

Loading DB routines from perl5db.pl version 1.07 Editor support available.

Enter h or `h h' for help\, or `man perldebug' for more help.

main​::(-e​:1)​: 0 DB\<1> print $.

DB\<2> print $. 0 DB\<3> print $. 0 DB\<4> print $. 0 DB\<5> print $. 0

Hmmm... Something very odd is happening here. I get the output 1\, 2\, 3 ... on all versions of Perl5\, while you and Jeff get zeroes. Ah! I'll bet you've got different variants of Term​::whatever installed.

Anyhow\, with the attached patch (for 5.6.0)\, all of this behaviour should go away.

Mike Guy

Inline Patch ```diff --- ./lib/perl5db.pl.orig Sun Mar 19 06:26:25 2000 +++ ./lib/perl5db.pl Sat Apr 29 13:54:01 2000 @@ -1698,8 +1698,6 @@ } sub gets { - local($.); - #; &readline("cont: "); } @@ -1804,6 +1802,7 @@ } sub readline { + local $.; if (@typeahead) { my $left = @typeahead; my $got = shift @typeahead; End of patch ```
p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

"Mike" == M J T Guy \mjtg@&#8203;cus\.cam\.ac\.uk writes​:   Mike> Hmmm... Something very odd is happening here. I get the   Mike> output 1\, 2\, 3 ... on all versions of Perl5\, while you and   Mike> Jeff get zeroes. Ah! I'll bet you've got different   Mike> variants of Term​::whatever installed.

I have Term​::ReadKey and Term​::ReadLine​::Perl installed

  Mike> Anyhow\, with the attached patch (for 5.6.0)\, all of this   Mike> behaviour should go away.

With your patch I now get​:

rabbit% perl5.6.0 -de 0 Default die handler restored.

Loading DB routines from perl5db.pl version 1.07 Editor support available.

Enter h or `h h' for help\, or `man perldebug' for more help.

main​::(-e​:1)​: 0   DB\<1> print $.

  DB\<2> print $.

  DB\<3> print $.

  DB\<4> print $.

  DB\<5>

Is that what should have happened?

p5pRT commented 20 years ago

From mcmahon@ibiblio.org

[RT_System - Sat Apr 29 02​:53​:42 2000]​:

"Mike" == M J T Guy \<mjtg \<!--c--> \at\ \<!--a--> cus.cam.ac.uk> writes​: Mike> Hmmm... Something very odd is happening here. I get the Mike> output 1\, 2\, 3 ... on all versions of Perl5\, while you and Mike> Jeff get zeroes. Ah! I'll bet you've got different Mike> variants of Term​::whatever installed.

I have Term​::ReadKey and Term​::ReadLine​::Perl installed

Mike> Anyhow\, with the attached patch \(for 5\.6\.0\)\, all of this
Mike> behaviour should go away\.

With your patch I now get​:

rabbit% perl5.6.0 -de 0 Default die handler restored.

Loading DB routines from perl5db.pl version 1.07 Editor support available.

Enter h or `h h' for help\, or `man perldebug' for more help.

main​::(-e​:1)​: 0 DB\<1> print $.

DB\<2> print $.

DB\<3> print $.

DB\<4> print $.

DB\<5>

Is that what should have happened?

Yes. $. isn't actually defined until something gets read from STDIN in the program being debugged. Since nothing has been read\, it's undef.

joe% perl -de 'while(\){print}' Default die handler restored.

Loading DB routines from perl5db.pl version 1.07 Editor support available.

Enter h or `h h' for help\, or `man perldebug' for more help.

main​::(-e​:1)​: while(\){print}   DB\<1> p $.

  DB\<2> s frejfejfe main​::(-e​:1)​: while(\){print}   DB\<2> p $. 1   DB\<3> s frejfejfe main​::(-e​:1)​: while(\){print}   DB\<3> s riejiejfreifjoeijeo main​::(-e​:1)​: while(\){print}   DB\<3> p $. 2   DB\<4> p $. 2   DB\<5> p $. 2   DB\<6>

The behavior should probably be documented specifically.

p5pRT commented 18 years ago

From @schwern

The debugger no longer sets $.

$ perl -de 0

Loading DB routines from perl5db.pl version 1.28 Editor support available.

Enter h or `h h' for help\, or `man perldebug' for more help.

main​::(-e​:1)​: 0   DB\<1> print $.

  DB\<2>

The code works the same in the debugger as it does on the command line​:

$ perl -de 0

Loading DB routines from perl5db.pl version 1.28 Editor support available.

Enter h or `h h' for help\, or `man perldebug' for more help.

main​::(-e​:1)​: 0   DB\<1> @​a = qw(A B C);

  DB\<2> x $a[0..3]\, $a[1..3] 0 'B' 1 'A'   DB\<3>

$ perl -wle '@​a = qw(A B C); print $a[0..3]\, $a[1..3]' Use of uninitialized value in range (or flip) at -e line 1. Use of uninitialized value in range (or flop) at -e line 1. Use of uninitialized value in range (or flip) at -e line 1. Argument "" isn't numeric in array element at -e line 1. BA

p5pRT commented 18 years ago

@schwern - Status changed from 'open' to 'resolved'

p5pRT commented 18 years ago

From @rgarcia

On 7/13/05\, Michael G Schwern via RT \perlbug\-followup@&#8203;perl\.org wrote​:

main​::(-e​:1)​: 0 DB\<1> @​a = qw(A B C);

DB\<2> x $a[0..3]\, $a[1..3]

Surely you mean @​a[0..3] here.

p5pRT commented 18 years ago

From @schwern

On Wed\, Jul 13\, 2005 at 10​:12​:25AM +0200\, Rafael Garcia-Suarez wrote​:

On 7/13/05\, Michael G Schwern via RT \perlbug\-followup@&#8203;perl\.org wrote​:

main​::(-e​:1)​: 0 DB\<1> @​a = qw(A B C);

DB\<2> x $a[0..3]\, $a[1..3]

Surely you mean @​a[0..3] here.

Just replicating what the bug claimed.

  main​::(-e​:1)​: 0   DB\<1> @​a = qw( A B C );

  DB\<2> x $a[0..3]\, $a[1..3]   0 'B'   1 'A'

-- Michael G Schwern schwern@​pobox.com http​://www.pobox.com/~schwern Don't try the paranormal until you know what's normal.   -- "Lords and Ladies" by Terry Prachett

p5pRT commented 18 years ago

From japhy@perlmonk.org

On Jul 13\, Michael G Schwern said​:

On Wed\, Jul 13\, 2005 at 10​:12​:25AM +0200\, Rafael Garcia-Suarez wrote​:

On 7/13/05\, Michael G Schwern via RT \perlbug\-followup@&#8203;perl\.org wrote​:

main​::(-e​:1)​: 0 DB\<1> @​a = qw(A B C);

DB\<2> x $a[0..3]\, $a[1..3]

Surely you mean @​a[0..3] here.

Just replicating what the bug claimed.

main​::(-e​:1)​: 0 DB\<1> @​a = qw( A B C );

DB\<2> x $a[0..3]\, $a[1..3] 0 'B' 1 'A'

Perhaps it behaves differently because $.'s value in the debugger is different from $.'s value in the program when it's run normally?

Since that is what $a[0..3] and $a[1..3] depend on.

-- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated\, we who for every service http​://japhy.perlmonk.org/ % have long ago been overpaid? http​://www.perlmonks.org/ % -- Meister Eckhart