Playing Sound in Perl script
A more portable way to get the path to paplay
(assuming it's there) might be to use File::Which
. Then you could get the path like:
use File::Which;my $paplay_path = which 'paplay';
And to play the sound asynchronously, you can fork
a subprocess:
my $pid = fork;if ( !$pid ) { # in the child process system $paplay_path, '/usr/share/sounds/gnome/default/alert/sonar.ogg';}# parent proc continues here
Notice also that I've used the multi-argument form of system
; doing so avoids the shell and runs the requested program directly. This avoids dangerous bugs (and is more efficient.)