Hey,
I'm currently writing an OO chat room in Perl and have bumped into a couple of issues I am unable to resolve easily.
My aim was to use CGI::Session to handle users, and Storable to handle messages. Both of these modules can store data structures which is important.
One of the first things I do in the chat script is get the messages. However if the "message response" is empty at this point there are two issues:
____________________________________________________________________
1)
"Magic number checking on storable file failed at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/_retrieve.al)"
This happens when a totally empty text file is retrieved, inevitably because the file isn't a "Storable file" yet. Is there a way that Storable can handle turning a file into a "Storable file" for me, or will I have to create some routine to do it myself?
____________________________________________________________________
2)
"Modification of non-creatable array value attempted, subscript -1"
While checking the last message a user has seen, I need to look each time for the last message id:
However if $messages (an array reference), is empty then I have problems with using $messages->[-1]->{id} even with a condition. Whats the alternative way around this?
____________________________________________________________________
Any advice will be greatly appreciated. Thanks alot,
Chris
I'm currently writing an OO chat room in Perl and have bumped into a couple of issues I am unable to resolve easily.
My aim was to use CGI::Session to handle users, and Storable to handle messages. Both of these modules can store data structures which is important.
One of the first things I do in the chat script is get the messages. However if the "message response" is empty at this point there are two issues:
____________________________________________________________________
1)
"Magic number checking on storable file failed at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/_retrieve.al)"
This happens when a totally empty text file is retrieved, inevitably because the file isn't a "Storable file" yet. Is there a way that Storable can handle turning a file into a "Storable file" for me, or will I have to create some routine to do it myself?
____________________________________________________________________
2)
"Modification of non-creatable array value attempted, subscript -1"
While checking the last message a user has seen, I need to look each time for the last message id:
Code:
my $messages = $chat_room->get_messages(handle => \&handle_get_messages);
$chat_room->update_my_user(id => $messages->[-1]->{id}) if ($messages);
However if $messages (an array reference), is empty then I have problems with using $messages->[-1]->{id} even with a condition. Whats the alternative way around this?
____________________________________________________________________
Any advice will be greatly appreciated. Thanks alot,
Chris