|
-
Oct 29th, 2001, 05:38 PM
#1
Thread Starter
Member
Playing a sound using PERL in WIn98
A friend wrote a script that works on XP and 2000 but not on my 98 machine. The script checks a log file and when certain text is matched it should paly a sound file but it doesn't work on WIn 98.
here's the script:
Code:
use strict;
#
# Parameters
#
my $ChatLog = "c:\\mythic\\camelot\\chat.log";
my $TerminatorString = "--END--";
my @ParserArray = (
"c:\\windows\\media\\tada.wav", "You successfully make",
"c:\\windows\\media\\ding.wav", "You fail to make",
"c:\\windows\\media\\tada.wav", "this will do nicely",
$TerminatorString, $TerminatorString );
#
# External stuff
#
use Win32::Sound;
#
# Set the sound volume.
#
Win32::Sound::Volume( '100%' );
#
# Recreate the chat log file. We don't want to read the chat log
# from the last session when the script starts up.
#
system( "copy $ChatLog $ChatLog.old" );
open( CHATLOG, ">$ChatLog" )
|| die( "Unable to clear chat log file: $ChatLog" );
close( CHATLOG );
#
# Open a read handle to DAoC's chat log.
#
open( CHATLOG, $ChatLog )
|| die( "Unable to open chat log file: $ChatLog" );
#
# Read loop.
#
while ( 1 )
{
while ( <CHATLOG> )
{
print( $_ );
#
# Match the input string against all parser array strings.
#
my $i = 1;
while ( !( $ParserArray[ $i ] =~ /$TerminatorString/ ) )
{
if ( /$ParserArray[ $i ]/ )
{
print( "MATCH with \"$ParserArray[ $i ]\"\n" );
#
# Play the sound associated with this string.
#
my $WavFile = $ParserArray[ $i - 1 ];
print( "PLAY $WavFile\n" );
Win32::Sound::Play( $WavFile );
}
$i = $i + 2;
}
}
#
#
print( "Sleeping to wait for more chat.log input...\n" );
sleep( 1 );
}
#
# Cleanup
#
close( CHATLOG );
If anyone has any suggestiosn on how to make this work, please let mek now ASAP!
Thanks,
--Kel
Last edited by kelemvor; Oct 30th, 2001 at 02:50 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|