Scarborough has asked for the wisdom of the Perl Monks concerning the following question:

I have referred to Perl in a Nutshell and found that I should be able to do this

$text->delete(0, 'end'); #$text being a Text object

But all I get is a Tk error message saying "0" is a bad index.

Anyone know whats happening here?

80% of success is just turning up - Woody Allen

Replies are listed 'Best First'.
Re: Tk text delete invalid index
by Ven'Tatsu (Deacon) on Oct 01, 2004 at 16:13 UTC
    Tk::Text boxe indexes start at Line 1, Character 0 or '1.0'. I'd guess it's complaining about trying to access the nonexistant line 0.
Re: Tk text delete invalid index
by Grygonos (Chaplain) on Oct 01, 2004 at 16:23 UTC

    Aye, I believe it should be

    $text->delete('1.0','1.0 end');
    if you look up how tk handles these indexes I believe (can't find link..going from memory) that the words such as end and lineend are modifiers of the given index. so 1.0 end modifies 1.0 to the index at the end..assuming end is a proper index (i have only used linend myself).

      end is it's own index, so it can be used alone, lineend and friends are modifiers on another index. So you can say 'end linestart' or '1.0 lineend' for the start of the last line or the end of the first line respectively.