Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Perl 5.36 warns for magic comparison

by hurricup (Pilgrim)
on Oct 15, 2023 at 10:34 UTC ( [id://11154956]=perlquestion: print w/replies, xml ) Need Help??

hurricup has asked for the wisdom of the Perl Monks concerning the following question:

According to the perldebguts:
Each array @{"_<$filename"} holds the lines of $filename for a file compiled by Perl. The same is also true for evaled strings that contain subroutines, or which are currently being executed. The $filename for evaled strings looks like (eval 34).
Values in this array are magical in numeric context: they compare equal to zero only if the line is not breakable.
But perl 5.36 warns in my debugger as: Argument "use v5.36;\n" isn't numeric in numeric eq (==) at
There is a simple comparison: if $lines[$lineno] == 0
Do I do something wrong?

Replies are listed 'Best First'.
Re: Perl 5.36 warns for magic comparison
by ikegami (Patriarch) on Oct 15, 2023 at 17:54 UTC

    Using

    #!/usr/bin/perl use strict; use warnings; use v5.36; say 'Hello, world!';

    In 5.38, we see:

    DB<1> use Devel::Peek; DB<2> Dump( ${"_<a.pl"}[8] ); SV = PVMG(0x55d8627958e0) at 0x55d86251ff80 REFCNT = 1 FLAGS = (IOK,POK,IsCOW,pIOK,pPOK) IV = 94387850872920 NV = 0 PV = 0x55d8628074b0 "say 'Hello, world!';\n"\0 CUR = 21 LEN = 32 COW_REFCNT = 1 DB<3> Dump( ${"_<a.pl"}[6] ); SV = PVMG(0x55d862786d50) at 0x55d86251fec0 REFCNT = 1 FLAGS = (POK,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x55d8627d7d50 "use v5.36;\n"\0 CUR = 11 LEN = 16

    See how "line 8" has IOK and POK, but "line 6" only has POK? That means that line 8 contains an integer in addition to the string, while line 6 contains only the string. This doesn't match the documentation.

    (As a side note, why 94387850872920? In hex, it's 55D862528858, which in the same range as the addresses being dumped. So it looks like it's not just a flag, but a pointer to something.)

    Note that the problem is limited to lines containing pragmas. The non-pragma unbreakable lines have IOK and a value of zero.

    DB<4> use Devel::Peek;Dump( ${"_<a.pl"}[5] ); SV = PVMG(0x55856a4198d0) at 0x55856a4e9630 REFCNT = 1 FLAGS = (IOK,POK,pIOK,pPOK) IV = 0 NV = 0 PV = 0x55856a486840 "\n"\0 CUR = 1 LEN = 16

    So only the lines with pragmas are broken. But this wasn't always the case. They used to be broken in a different way. Here with 5.34, we see that pragmas were once breakable.

    DB<2> Dump( ${"_<a.pl"}[6] ); SV = PVMG(0x55874ddaf680) at 0x55874db508a8 REFCNT = 1 FLAGS = (IOK,POK,pIOK,pPOK) IV = 94039612799016 NV = 0 PV = 0x55874db739a0 "use v5.10;\n"\0 CUR = 11 LEN = 16

    I'm guessing that when they fixed the bug marking pragmas as breakable, they forgot to set the IOK flag.

    Bug report

      Fixed in (upcoming) 5.40.

Re: Perl 5.36 warns for magic comparison
by choroba (Cardinal) on Oct 15, 2023 at 14:08 UTC
    Update: After enabling warnings in the command line, I got the same warnings in 5.39.4. So, disregard this node.

    You don't show enough for us to answer. I tried the following in two different versions of Perl (one of them older and one newer than 5.36).

    I saved the following script as 2.pl:

    #!/usr/bin/perl use strict; use feature qw{ say }; use warnings; my $x = 10; for my $i (1 .. 10) { $x += $i; }

    I then ran

    perl -d 2.pl
    using both the Perl versions.

    5.26.1:

    DB<1> @lines=@{"_<2.pl"} ; for my $i (0 .. $#lines) { CORE::say $lin +es[$i] == 0 } 1 1 1 1

    5.39.4 (blead):

    DB<1> @lines=@{"_<2.pl"} ; for my $i (0 .. $#lines) { CORE::say $lin +es[$i] == 0 } 1 1 1 1 1 1 1

    The output is different, but there's no warning.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      You don't get any warnings because you forgot to enable warnings.

Re: Perl 5.36 warns for magic comparison
by Anonymous Monk on Oct 15, 2023 at 15:26 UTC

    I get no warning out of Perl 5.36.1 from the following script:

    #!/usr/bin/env perl
    
    use strict;
    use warnings;
    
    use v5.36;
    
    say 'Hello, world!';
    

    using the commands:

    perl -d dbg.pl
      DB<1> @lines = @{"_<dbg.pl"}; say $_ == 0 for @lines;
    1
    1
    1
    1
    1
    1
    1
    1
    
    
      DB<2> q                                                                       
    

    I also tried 5.36.0, with the same output and the same lack of a warning.

    Maybe if you exhibited a small, self-contained example, giving the exact code and exact debugger commands to trigger the problem?

      You don't get any warnings because you forgot to enable warnings.

        You don't get any warnings because you forgot to enable warnings.

        I see use warnings;

        Is this not enabling warnings?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11154956]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found