perl 스크립트를 닫으면 종료됩니다. 그것은 아무것도 기억할 수 없으며, 더 이상 존재하지 않습니다. 그러나 스크립트를 만들어 위치를 파일에 저장할 수 있으며 시작시 파일에서 위치를 읽을 수 있습니다. 다음의 예를 참조하십시오 : 당신은 여러 파일을 열하려는 경우
#!/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;
}
을, 당신은 위치와 함께 파일의 경로를 기억해야합니다.
감사합니다. 정말로 해결되었습니다! – dileepmani