HeyYou has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: File I/O in Perl/Tk
by chromatic (Archbishop) on Jan 02, 2006 at 05:08 UTC

    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() );
      Yeah I noticed I forgot the -> get(); right after I posted. Thanks for the tips on using private variables for more efficeint code.