Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

by JSchmitz (Canon)
on Jul 08, 2001 at 04:16 UTC ( #94784=sourcecode: print w/replies, xml ) Need Help??
Category: CGI Programming
Author/Contact Info
Description: Allows you to play midi files on your website.

# To run this script put the following line into the body of your html
+ page.
# <!--#exec cgi="/path/to/bsmidi.cgi"-->

$datafile = "playlist.txt";
 # Location of the playlist file.
 # An example is included in the zip file.

$width = "0";
 # The width of the control box.

$height = "0";
 # The height of the control box.

$autostart = "true";
 # Have the midis automatically play (true=yes, false=no)

$loop = "false";
 # Have the song repeat (true=yes, false=no)

$showtitle = "true";
 # Show song title. (true=yes, false=no)

$fntstyle = "Arial";
 # Title Font Style.

$fntsize = "4";
 # Title Font Size.

$fntbold = "true";
 # Is Title Bold? (true=bold, false=plain)

open (GETDATA, "$datafile");
@Data = <GETDATA>;
close GETDATA;

srand(time ^ $$);
$number = rand(@Data);
$line = @Data[$number];

chomp ($line);
($title, $midi) = split(/\|/, $line);

print "Content-type: text/html\n\n";

if ($showtitle =~ /true/i)
    print "<font size=\"$fntsize\" face=\"$fntstyle\">";
    if ($fntbold =~ /true/i) {print "<strong>";}
    print "$title";
    if ($fntbold =~ /true/i) {print "</strong>";}
    print "</font>\n";

print "<embed src=\"$midi\" width=\"$width\" height=\"$height\" autost
+art=\"$autostart\" loop=\"$loop\"><noembed><bgsound src=\"$midi\" loo

exit (0);
Replies are listed 'Best First'.
by cleen (Pilgrim) on Jul 09, 2001 at 01:24 UTC
    since you have $showtitle = "true"; than $showtitle =~ /true/i is an un-needed regex. IMHO you should just do $showtitle eq "true". Same goes for the rest of the scalers with the same attributes.

    You also might want to incorporate into your script so you can edit attributes of your script via url instead of going and editing the program..IE:
    #!/usr/bin/perl use strict; use CGI qw/:standard/; my $c = new CGI; my $datafile = "/full/path/to/playlist.txt"; my $width = $c->param("width") || 0; my $height = $c->param("height") || 0; my $autostart = $c->param("autostart")|| "true"; my $loop = $c->param("loop") || "false"; my $showtitle = $c->param("showtitle")|| "true"; my $fntstyle = $c->param("fntstyle") || "Arial"; my $fntsize = $c->param("fntsize") || 4; my $fntbold = $c->param("fntbold") || "true"; open(GETDATA, "$datafile"); @Data = <GETDATA>; close(GETDATA); srand(time & $$); my $number = rand(@Data); my $line = @Data[$number]; chomp($line); ($title,$midi) = split(/\|/, $line); print header; if ($showtitle eq "true") { print "<font size=\"$fntsize\" face=\"$fntstyle\">"; print "<strong>" if $fntbold eq "true"; print "$title"; print "</strong>" if $fntbold eq "true"; print "</font>\n"; } print "<embed src=\"$midi\" width=\"$width\" height=\"$height\" autost +art=\"$aut ostart\"l +oop=\"$loop\"><noembed><bgsound src=\"$midi\" loop=true></noembed></e +mbed>\n"; exit (0);

    happy coding.
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://94784]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2016-10-24 07:39 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (303 votes). Check out past polls.