0

I have to read a bin file in perl/tk. I have been able to read and open the file, but the read in file only has every other line from the original file. I am using following to open the file.

my @contents;
open(FILE,"example_data4.bin") or die"cant open file: $!";
@contents = <FILE>;
$txt->insert('end',@contents);

But this program only reads 1,3,5,7..... lines from the original file.

Can anyone help.

Thanks

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by crb3
0

I ran a quick test and had the same problem you did; it would only get the odd numbered lines. I do not have much experience with Tk, but I think second argument to insert must be scaler. Thus, this will get all your lines:

#! /usr/bin/perl
use Tk;

$mw = MainWindow->new;
$txt = $mw->Text ()->pack ();
open my $fh, '<', 'test.txt' or die $!;
@contents = <$fh>;
foreach my $line (@contents) {
        $txt->insert ("end", $line);
}
MainLoop;
0

From reading "man Tk::Text" (I assume that's the widget you're using), it would appear that every other line in your unrolled array was treated as a taglist rather than character-text. (I've only ever stuffed text as single-line scalars into a Text widget, but I went looking for what could be causing your problem.)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.