in reply to text widget in Perl/Tk question

Hi Anonymous Monk,

Could you post the code you are using?
You can read a file and place each line into the text widget as it is being read with this:

$text = $mw->Scrolled("Text")->pack(); open( FILE, "MyText" ) or die "Arghh...$!\n"; while( <FILE> ) { $text->insert('end', $_ ); } close FILE;


Hope this helps,

-Katie.

Replies are listed 'Best First'.
Re: Re: text widget in Perl/Tk question
by Anonymous Monk on Oct 30, 2002 at 06:15 UTC
    Yes the code above is what I am using at the moment but the problem is when I open the same file in TextPad for instance, TextPad opens it in no time whereas when I use the code above in Perl/Tk, it takes ages to open it. Is this the limitation of the text widget and can I do something about it? Thanks
      Well, certainly each call to $text->insert takes time. You can do it with just one call, like this:
      { local $/; $text->insert('end', <FILE> ); }
      That will insert the entire file at once.

      However, if the file is really large, you will always have problems trying to hold the entire file in memory at once. Good text editors are smart enough to page out the parts of the file not being viewed, in an efficient manner. You may have to resort to this kind of trick.