Consecutive Numbers

I

Ilya Zakharevich

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Ilya Zakharevich
[A complimentary Cc of this posting was NOT [per weedlist] sent to
Graham Drabble
I have a file that contains a list of numbers. I'm trying to process
the file to find out how many rows start with 4 consecutive digits
(either ascending or decending). Currently I've got

I'm puzzled at all complications: what is wrong with using something like

my $four = substr $in, 0, 4;
print 'OK' if length $four == 4 and
(0 <= index '0123456789', $four or 0 <= index '9876543210', $four);

Or one can try something like

my $four = substr $in, 0, 4;
print 'OK' if length $four == 4 and
0 <= index "0123456789\x{FFFFFFFF}9876543210", $four;

for its speed. However, the Unicode overhead can eat the advantages
of fewer opcodes to dispatch...

Yours,
Ilya

P.S. Here I use the fact that utf8 character repertuar is larger than
UTF-8 one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top