On Sat, May 29, 2004 at 02:39:53PM -0700, Rob Richardson wrote: > Greetings!
Hello Earthman! > My program was compiling and running. It was giving me strange results > from my print() functions. One of the list members was kind enough to > point out my mistake. (I was putting "$user->LastName()" into a string > to be printed.) I fixed it. Now I my program doesn't compile, and > it's giving me an error message that makes no sense to me: > > Can't use string ("UserList") as a HASH ref while "strict refs" in use > at UserList.pm line 66, <USERLIST> line 1. This is not a compile time message, it is a run time message. > Here is the function containing line 66: > > sub GetUser > { > my $self = shift; > my $userName = shift; > my $user = new User; Creating a new object here doesn't seem useful. you assign to $user in both branches below. > trace ("Getting user for login name $userName\n"); > > # The following line is line 66 > if (exists $self->{'users'}->{$userName}) And the message means that $self->{users} contains the string "UserList" rather than the hash reference you were presumably expecting. > { > $user = $self->{'users'}->{$userName}; > } > else > { > $user = new User; > $user->{'loginName'} = 'unknown'; > } > return $user; > } > > UserList.pm contains the "UserList" package, which contains the > UserList class and its methods. UserList maintains a list of users in > a hash keyed by the user's login name. > > At line 66, the variable $userName contains "interrobang". "UserList" > is not being used as a hash reference or as anything else at this > point, as far as I know. What could be causign this error? It would appear that you have assigned to $self->{users} the string "UserList" rather than an object of the class UserList. > This is not the first time a compile error has shown up in a previously > running program. I need to learn PHP. Well, Perl is not for everyone. You might find PHP more to your taste. Or Java. Or C#. Or Ruby. Or COBOL. Or Intercal. Who can say? Run time errors like this can show up when you do something you shouldn't have done. Having strict refs turned on has helped uncover it. Now you just need to track down where the incorrect assignment took place. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>