- 
                Notifications
    You must be signed in to change notification settings 
- Fork 602
Allow ${0x10}, ${0b10000} and ${0o20} to be used as aliases for $16 under use strict. #20014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Prior to this patch ${0x10} would require "no strict refs", with this patch
it is a legal alternative spelling for $16, likewise with ${0b10000},
and explicit octal (eg, with 0o prefix) as well. Note that ${0x010} and
${0b00010000} and similar are also allowed and will both also map to $16.
Since these values are constant it seems reasonable to treat them like
their decimal equivalents. Note that $0x10 does not work as one might
think, it parses as $0 x 10, only ${0x10} is allowed, similarly
$0b10 is forbidden, but ${0b10} is not. Note that $::0x10 and $::0b10
are NOT digits vars equivalent to $16 and $2, but rather $main::0x10
and $main::0b10.
    11c1920    to
    1753a64      
    Compare
  
    | } | ||
| if (shift) { | ||
| STRLEN len = PL_bufend - s; | ||
| I32 flags = PERL_SCAN_SILENT_ILLDIGIT | PERL_SCAN_DISALLOW_PREFIX; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider setting the PERL_SCAN_ALLOW_UJNDERSCORES flag? (to allow things like 0b11_00_1_1)
| if (flags & PERL_SCAN_GREATER_THAN_UV_MAX || d+len >= e) | ||
| Perl_croak(aTHX_ "%s", ident_too_long); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test for the flags & PERL_SCAN_GREATER_THAN_UV_MAX condition(?)
The error in that case might also be a bit misleading:
$ ./perl -wle 'use strict; print ${0x1ffffffffffffffff};'
Integer overflow in hexadecimal number at -e line 1.
Hexadecimal number > 0xffffffff non-portable at -e line 1.
Identifier too long at -e line 1.
| Personally I don't know if I like this/if this change is a good idea; As noted:  But the real question is what did the user intend? Footnotes
 | 
| On Mon, 1 Aug 2022 at 15:56, Bram ***@***.***> wrote:
 Personally I don't know if I like this/if this change is a good idea;
 As noted: $0xA isn't a valid variable but $::0xA is.
 Right now: using ${0xA} triggers an error under use strict;
 after this PR it no longer will.
 But the real question is what did the user intend?
 If someone is using $::0xA as var (which *I* consider a bad idea) then
 they might expect that ${0xA}1
 <#m_-7528345075786139255_user-content-fn-1-b3720c9c0a55e89bd8dcee6d67c21772>
 resolves to the same var. (It doesn't(/never did) but at least before this
 PR use strict will complain where as now it might (silently) do the wrong
 things).
 Footnotes
    1.
    in package main ↩
    <#m_-7528345075786139255_user-content-fnref-1-b3720c9c0a55e89bd8dcee6d67c21772>
 —
 Reply to this email directly, view it on GitHub
 <#20014 (comment)>, or
 unsubscribe
 <https://github.com/notifications/unsubscribe-auth/AAAZ5R6CTUYC73RDUS5UI5LVW7JSRANCNFSM55BAYNZQ>
 .
 You are receiving this because you authored the thread.
 Yeah, I think you have convinced me. It was a nice way to prove to myself I
understood what S_scan_ident() was doing but it is not really necessary and
maybe it would open a can of worms that we dont need to open.  I'll leave
it open for a few days to see if anyone says "god yes please" so you and
they can debate it out, but if nobody replies in a few days i'll close it.
BTW, regardless I do appreciate the feedback you have given on this, its
been helpful to push me to learn some esoterica I hadnt needed to learn
yet. :-) I hope it hasn't consumed too much of your time.
cheers,
Yves… -- 
perl -Mre=debug -e "/just|another|perl|hacker/" | 
| On second thought... Lets not. | 
This PR assumes that the commit in #20000 will be merged and includes it for now.
Treat
${0x10}as$16and allowed under strict, similarly${0b10000}and${0o20}. Without strict they would resolve to$16as well, but would be treated as symbolic references. Since they are constants and since "all digits vars always exist", it doesn't seem necessary to treat them as symbolic references and forbid this usage under use strict.