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

I'm trying to write an interface to Win32::Sound into X-Chat, so Windows users can have a /sound command (and so some events can play sounds). Also, I'm trying to fork() this Win32::Sound::Play() off, so other events can occur without waiting for the sound to finish playing. However, during some events that call my sub, X-Chat crashes. I say "some events" because this doesn't occur everytime the sub is called, but it always occurs when the sub is called from a particular event. From that, I'm not sure if it's due to my code, fork() on Win32, or X-Chat itself. Here's the sub that I'm using to play wavs:
sub soundplay { my($file) = shift; if ($win32) { # Are we using Win32 X-Chat? if ($fork) { # Does the user want to fork()? my($pid) = fork(); if (!$pid) { if (-e $file) { Win32::Sound::Play($file); } elsif (-e "sounds/$file"){Win32::Sound::Play("sounds/$file");} elsif (-e "data/$file") { Win32::Sound::Play("data/$file"); } elsif (-e "dcc/$file") { Win32::Sound::Play("dcc/$file"); } return 1; } return 1; } if (-e $file) { Win32::Sound::Play($file); } elsif (-e "sounds/$file"){Win32::Sound::Play("sounds/$file");} elsif (-e "data/$file") { Win32::Sound::Play("data/$file"); } elsif (-e "dcc/$file") { Win32::Sound::Play("dcc/$file"); } } return 1; }
And a calling event that causes a crash:
sub print_whois_chans_or_oper { my(@line) = split(" ",$_[0]); if ($_[0] eq " $line[0] is an IRC Operator") { IRC::print(" [\002i\002rcop\002:\002 $line[0] is an IRCop\n"); soundplay("ohmy.wav") if $sounds; # Play if user wants sounds } else { IRC::print(" [\002c\002hannels\002:\002 @line[1..$#line]\n"); } return 1; }
I understand that this is Perl, not X-Chat, discussion, but since I'm unsure if my code is at all sound, I thought I'd ask. Would love any input you folks have! Thanks in advance.