Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8141577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:33:27+00:00 2026-06-06T12:33:27+00:00

I just wrote a very simple perl tk script to read a huge text

  • 0

I just wrote a very simple perl tk script to read a huge text file and display it with Text widget and attached it to Scrollbar widget. Now my problem is that each time i run the script , it displays from the first sentence ( of the whole text file ) onwards. How can i make the script remember my position in the text and display the same area when i quit and start the script again i.e if i read the 1000 th line of the text and quit the script, script should show the 1000th line onwards when i again run it. ( or in other words remember the scroll position)

I am not a professional in perl tk nor perl but trying my best to learn it. Please give a reply explaining it lucidly

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:33:28+00:00Added an answer on June 6, 2026 at 12:33 pm

    If you close your perl script, it ends. It cannot remember anything, it’s not there anymore. But, you can make the script to save the position to a file, and upon startup, you can try to read the position from the file. See the following example:

    #!/usr/bin/perl
    use warnings;
    use strict;
    
    use Tk;
    
    my $file   = 'input.txt';
    my $config = '.viewtext.conf';
    
    my $mw = MainWindow->new(-title => 'Remember Position');
    my $t = $mw->Scrolled("Text", -scrollbars => 'se')->pack;
    my $b = $mw->Button(-text => 'Quit', -command => \&quit)->pack;
    
    
    open my $FH, '<', $file or die $!;
    $t->Contents(<$FH>);
    close $FH;
    
    if (-f $config) {
        open my $FH, '<', $config or die $!;
        my ($x0, $x1, $y0, $y1) = split / /, <$FH>;
        $t->xviewMoveto($x0);                            # Here we restore the saved position
        $t->yviewMoveto($y0);
    }
    
    MainLoop();
    
    sub quit {
        open my $CONF, '>', $config or die $!;
        print {$CONF} join ' ', $t->xview, $t->yview;    # This is the current position
        close $CONF;
        $mw->destroy;
    }
    

    If you are going to open several different files, you have to remember the path to the file together with the position.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a very simple perl script, and now I want to make it
I just wrote a very simple Expect script for wrapping around rsync, but it
I wrote a script in php. It's very simple, it just multiplies a typed
I just began learning PHP. I've installed php5 on Linux and wrote very simple
I wrote some very simple code since I'm just starting C++ and I want
I wrote a very simple web form that allows my user to view text
I wrote a very simple application which just get the current location of the
I'm trying to write a very lightweight build script which will basically just get
I just wrote a PHP login script, and what I'm trying to accomplish is
I use mechanize gem to crawl websites. I wrote a very simple, one-threaded crawler

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.