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' => $prop->{'UserDirectory'} || undef }; bless($self); return $self; } sub RegisterUser{ my $self = shift; #--> Hash Reference to User Properties #--------------------------------------> my $userProps = shift; my $userFileName = q{\$userProps->{'LoginName'}.usr}; $self->{'UserFile'} = $userFileName; #--> Make a fuul path to the user file for creation #---------------------------------------------------> my $userFile = $self->{UserDirectory}.$userFileName; #--> Print User information to a file, this becomes the user file #------------------------------------------------------------------> $self->write_file_Hash($userFile, %$userProps); } sub getUserInfo { my $self = shift; my $f = shift; my %userInfo; my $fullFilePath = $f.$self->{'UserFile'}; open (FILE, "< $fullFilePath"); while (){ 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; #--> Grab incoming Arguments #----------------------------> my ($file,%data) = @_; #--> Make Data hash empty unless something is in it, don't want any undefines #------------------------------------------------------------------------------> %data = () unless %data; #--> Open file and print hash in the format: Key=Value #-------------------------------------------------------> open (FH, ">> $file"); while ( my ($key, $value) = each(%data) ) { print FH "$key=$value\n"; } close FH; } 1; __END__