Line number inconsistency

Discussion in 'Perl Misc' started by Daniel Pfeiffer, Dec 18, 2005.

  1. 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

    --
    lerne / learn / apprends / lär dig / ucz się Esperanto:
    http://lernu.net / http://ikurso.net
     
    Daniel Pfeiffer, Dec 18, 2005
    #1
    1. Advertising

  2. Daniel Pfeiffer wrote:
    > 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
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Dec 19, 2005
    #2
    1. Advertising

  3. Daniel Pfeiffer

    Guest

    John W. Krahn wrote:
    > 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).
     
    , Dec 19, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Krishan

    color format inconsistency?

    Krishan, Sep 13, 2003, in forum: Java
    Replies:
    2
    Views:
    702
    Tim Tyler
    Sep 14, 2003
  2. Hugo
    Replies:
    10
    Views:
    1,346
    Matt Humphrey
    Oct 18, 2004
  3. kaushikshome
    Replies:
    4
    Views:
    796
    kaushikshome
    Sep 10, 2006
  4. scad
    Replies:
    23
    Views:
    1,196
    Alf P. Steinbach
    May 17, 2009
  5. Marek Stepanek
    Replies:
    12
    Views:
    425
    Peter J. Holzer
    Sep 2, 2006
Loading...

Share This Page