Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Match operator fails for elements 100 and higher

by Crackers2 (Vicar)
on Nov 03, 2010 at 21:07 UTC ( #869324=note: print w/ replies, xml ) Need Help??


in reply to Match operator fails for elements 100 and higher

Interestingly, things start working again at 999. i.e.

m/$mystrings[998]/; # Fails m/$mystrings[999]/; # Works m/$mystrings[1000]/; # Works
Deparse shows it's indeed parsed differently, but doesn't show why:
> perl -MO=Deparse x Global symbol "$mystrings" requires explicit package name at x line 10 +. x had compilation errors. use strict 'refs'; my(@mystrings) = 'string' x 200; $mystrings[99]; "$mystrings[100]"; /$mystrings[999]/; /${'mystrings'}[998]/;

Update: These values also work: 111, 222, 333, 444, 555, 666, 777, 888. And apparently above 1000 it's not simple either. The first working ones after 1000 are: 1110, 1111, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1131, 1141, 1151, 1161, 1171, 1181, 1191, 1311, 1333, 1411

Overall, there's 393 values from 0 to 10,000 for which it works. The rest fail.


Comment on Re: Match operator fails for elements 100 and higher
Select or Download Code
Re^2: Match operator fails for elements 100 and higher
by thrasher (Initiate) on Nov 03, 2010 at 21:13 UTC
    I found a work-around, just use a different array to index the string array instead of using numbers:
    my @mystrings = ("string") x 200; my @i = 0..$#mystrings; m/$mystrings[$i[100]]/;
    Thanks for your help. Should I report this issue?

      Simpler workaround (or maybe it's the right thing to do in the first place) is this:

      m/${mystrings[100]}/;
        Yup, there is ambiguity as to whether the [999] is a character class or array index.

        Odd that the contents should determine how it's parsed though.

        print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://869324]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (19)
As of 2014-10-21 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (110 votes), past polls