<?xml version="1.0" encoding="windows-1252"?>
<node id="595105" title="ikkon's scratchpad" created="2007-01-17 12:18:17" updated="2007-01-17 07:18:17">
<type id="182711">
scratchpad</type>
<author id="583775">
ikkon</author>
<data>
<field name="doctext">
I am having problem trying to write user info to a file then be able to retrieve that info in a hash.

here is the pl file:
&lt;code&gt;
#!/usr/bin/perl -w

use lib 'modules';
use ChatUtils;
use strict;
use CGI qw(fatalsToBrowser);
use warnings;
use diagnostics;


my $q = new CGI;
print $q-&gt;header( "text/plain" );#C:\WEB_ROOT\PerlChat\userdir

my $UtilObj = new ChatUtils({
	UserDirectory =&gt; '/userdir'
});

my %userProps = (
	LoginName =&gt; 'Ikkon',
	LoginPass =&gt; 'Chaos',
	UserName =&gt; 'Ben'
);

my $userDir = $UtilObj-&gt;{'UserDirectory'};
$UtilObj-&gt;RegisterUser(\%userProps);

my %getUserInfo = $UtilObj-&gt;getUserInfo($userDir);
while ( my ($key, $value) = each(%getUserInfo) ) {
     print "$key =&gt; $value\n";
}
&lt;/code&gt;

#### ChatUtil.pm
&lt;code&gt;
package ChatUtils;

use strict;
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

$VERSION = '1.0';



sub new
{
	my ($class, $prop) = @_;
	
	my $self = {

				'UserDirectory'	=&gt; $prop-&gt;{'UserDirectory'} || undef
							
	};
	bless($self);	
	return $self;
}

sub RegisterUser{
	my $self = shift;	
	#--&gt; Hash Reference to User Properties
	#--------------------------------------&gt;
	my $userProps = shift;
	my $userFileName = q{\$userProps-&gt;{'LoginName'}.usr};
	$self-&gt;{'UserFile'} = $userFileName;
	#--&gt; Make a fuul path to the user file for creation
	#---------------------------------------------------&gt;
	my $userFile = $self-&gt;{UserDirectory}.$userFileName;
	#--&gt; Print User information to a file, this becomes the user file
	#------------------------------------------------------------------&gt;
	$self-&gt;write_file_Hash($userFile, %$userProps);
}

sub getUserInfo {
	my $self = shift;
	my $f = shift;
	my %userInfo;
	my $fullFilePath = $f.$self-&gt;{'UserFile'};
	open (FILE, "&lt; $fullFilePath");
		while (&lt;FILE&gt;){
			chomp;                  # no newline
			s/#.*//;                # no comments
			s/^\s+//;               # no leading white
			s/\s+$//;               # no trailing white
			next unless length;     # anything left?
			my ($var, $value) = split(/\s*=\s*/, $_, 2);
			$userInfo{$var} = $value;
		} 
	close FILE;
	return %userInfo;
}


sub write_file_Hash {
	my $self = shift;
	#--&gt; Grab incoming Arguments
	#----------------------------&gt;
	my ($file,%data) = @_;
	#--&gt; Make Data hash empty unless something is in it, don't want any undefines
	#------------------------------------------------------------------------------&gt;
	%data = () unless %data;
	#--&gt; Open file and print hash in the format: Key=Value
	#-------------------------------------------------------&gt;
	open (FH, "&gt;&gt; $file");
	while ( my ($key, $value) = each(%data) ) {
        print FH "$key=$value\n";
    }
	close FH;
}

1;

__END__

&lt;/code&gt;


I am not sure what I am doing wrong  here is the error i am getting:
readline() on closed filehandle FILE at modules/ChatUtils.pm line 45 (#2)
    (W closed) The filehandle you're reading from got itself closed sometime
    before now.  Check your control flow.
    
Content-Type: text/plain; charset=ISO-8859-1

</field>
</data>
</node>
