Line number inconsistency

D

Daniel Pfeiffer

I recently stumbled over a design bug, and there doesn't even seem to be a
clear warning about it in the docs: columns (e.g. in strings), like all
indices, count from 0, but file lines count from 1. That leads to absurd
equivalences like

5..7 and print while <>;

does the same as

print +(<>)[4..6];

Worse, if you do

0..9 and print while <>;

that will not emulate head, instead the flip-flop will never become true.

I guess it's too late to make line numbers behave, but there should be a big
warning in the docs!

coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer
 
J

John W. Krahn

Daniel said:
I recently stumbled over a design bug, and there doesn't even seem to be
a clear warning about it in the docs: columns (e.g. in strings), like
all indices, count from 0, but file lines count from 1.

Get one of your non-programmer friends to open a document in their favourite
text editor and then tell them to go to line 0.

That leads to absurd equivalences like

(In your opinion.)

5..7 and print while <>;

does the same as

print +(<>)[4..6];

It prints the same lines but it doesn't do the same thing.

Worse, if you do

0..9 and print while <>;

that will not emulate head, instead the flip-flop will never become true.

Probably because $. can never be equal to 0.

I guess it's too late to make line numbers behave, but there should be a
big warning in the docs!

Then I guess you could also teach everyone in the world that their documents
now start at line zero instead of what they assumed is actually line one.


John
 
U

usenet

John said:
Get one of your non-programmer friends to open a document in their favourite
text editor and then tell them to go to line 0.

in vi, :0 takes me to... waitaminute - it does the same thing as :1
:^O
Then I guess you could also teach everyone in the world that their documents
now start at line zero instead of what they assumed is actually line one.

I suppose if it really bothers the OP, s/he can read the file into an
array (or process it array-style with File::Tie).
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top