Hi monks,I have written a small script to open a file using perl tk . Whenever i opened the input file "./test.txt" (original file) consists 10-20 lines of data. If I will open the same file through my script it will show very few lines and it is not saving any changes into original file.

#!/usr/bin/perl -w use warnings; use strict; use Tk; use Tk::FileSelect; my $mw = MainWindow->new; $mw->configure( -background => 'black', -foreground => 'white' ); $mw->geometry( "400x300" ); $mw->title( "Multiple Windows Test" ); my $curr_path = "/root/test.txt"; my $button1 = $mw->Button( -text => "view Results", -background => "cyan", -command => \&button1_sub )->pack( -side => "right" ); $mw->Button( -text => "Exit", -command => sub { exit } ) ->pack( -side => "bottom" ); sub button1_sub { my $subwin1 = $mw->Toplevel; $subwin1->geometry( "500x400" ); $subwin1->title( "Sub Window #1" ); my $fh; open( $fh, '+<', "$curr_path" ) or die $!; my @contents = <$fh>; close( $fh ); my $sublable = $subwin1->Scrolled( 'Text', -scrollbars => 'oso +e', )->pack; $sublable->insert( 'end', @contents ); my $subwin_button = $subwin1->Button( -text => "Close window", -command => [$subwin1 => 'destroy'], )->pack( -side => "bottom" ); #=================Creating save buttion on subwindow =========== my $save_button = $subwin1->Button(-text=>'save', -command =>\&get_save, -background =>'cyan' )->pack(-side=>'right'); } MainLoop; sub get_save { my $dst = $mw->getSaveFile( -initialdir => '/root/', -defaultextension => '.txt', -initialfile =>'test.txt', -title => 'Save', -filetypes => [ [ 'myfiles' => '.txt' ], [ 'All files' => '*' ], ], ); $dst ||= '<undef>'; warn "dst=$dst"; }

Here is my input file "test.txt"

2 3 4 5 6 7 8 9 a b c d e f

If i will open the same file through my script it displays the following contents

1 3 5 7 9 b d f

In reply to File contents are not displaying in Perl tk by vr786

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.