File I/O in Perl/Tk
HeyYou
created: 2006-01-01 22:24:06
I'm writing a permanant record program for my church and I first did it in command line and the File I/O worked fine, but when I put the concepts I used in that program into a GUI it didn't work part of the program is
sub enter_father {
  $student = $name_ent -> get;
  open studentfile, ">>", $student;
  $file_array[6] = $father_ent;
  print studentfile ($file_array[6]);
  close studentfile;
}
although there are more entris and all the end file ends up having content like this,
SampleNameTk::Entry=HASH(0x84a8644)Tk::Entry=HASH(0x84a8a4c)Tk::En
try=HASH(0x84a8bcc)Tk::Entry=HASH(0x84a8dc4)Tk::Entry=HASH(0x84a
8fbc)Tk::Entry=HASH(0x84a91b4)Tk::Entry=HASH(0x84a93ac)Tk::Entry
=HASH(0x8499b58)Tk::Entry=HASH(0x8499d50)Tk::Entry=HASH(0x8499f4
8)Tk::Entry=HASH(0x849a140)Tk::Entry=HASH(0x849a338)Tk::Entry=HA
SH(0x849a530)Tk::Entry=HASH(0x849a728)Tk::Entry=HASH
The name shows up, but nothing else
Reaped: Re: File I/O in Perl/Tk
created: 2006-01-01 23:26:13
This node was taken out by the NodeReaper on 2006-01-02 00-53-50
Reason: [jdporter]: troll trash

You may view the original node and the consideration vote tally.

Re: File I/O in Perl/Tk
created: 2006-01-02 00:08:03

It's not clear to me from your code, but I think you need to call $father_end->get() to retrieve the contents of the father entry box.

Style-wise, I also recommend not using global variables -- instead passing variables to your subroutines:

sub save_from_entry_widget
{
    my ($widget, $filename) = @_;
    my $text                = $widget->get();
    open my $fh, '>>', $filename or die "Cannot append to '$filename': $!\n";
    print $fh $text;
}

Then call this with:

save_from_entry_widget( $father_ent, $name_ent->get() );
Re^2: File I/O in Perl/Tk
created: 2006-01-04 19:58:26
Yeah I noticed I forgot the -> get(); right after I posted. Thanks for the tips on using private variables for more efficeint code.

perlmonks.org content © perlmonks.org and chromatic, HeyYou, NodeReaper

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03