Gossamer Forum
Home : General : Perl Programming :

Error with my script...

Quote Reply
Error with my script...
When I tried running a script I made I recieved the following error
Code:
foreach $i(%sounds){
if ($sounds{'$i'} eq "$sounds{$FORM{'input'}}") { print "<option selected value=\"$sounds{'$i'}\">$i<\/option\>\n"; }
else { print "\<option value\=\"$sounds{'$i'}\"\>$i\<\/option\>\n"; }
}
Can you tell me what is wrong, I am new at Perl.

------------------
- YellowKard -

Quote Reply
Re: Error with my script... In reply to
Try the following codes:

Code:
foreach $i ( keys %sounds) {
if ($sounds{'$i'} eq "$sounds{$FORM{'input'}}") { print "<option selected value=\"$sounds{'$i'}\">$i<\/option\>\n"; }
else { print "\<option value\=\"$sounds{'$i'}\"\>$i\<\/option\>\n"; }
}

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: Error with my script... In reply to
I now get the error
Quote:
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:



String found where operator expected at D:\home\yellowkardtentex\www\cgi-bin\jukebox.cgi line 28, near ""17""
(Missing semicolon on previous line?)
syntax error at D:\home\yellowkardtentex\www\cgi-bin\jukebox.cgi line 28, near ""17""
syntax error at D:\home\yellowkardtentex\www\cgi-bin\jukebox.cgi line 56, near "$i ("
Execution of D:\home\yellowkardtentex\www\cgi-bin\jukebox.cgi aborted due to compilation errors.

The working script (or should I say not working) can be viewed at http://yellowkard.tentex.com/cgi-bin/jukebox.cgi

The source can be viewed at http://yellowkard.tentex.com/cgi-bin/jukebox.cgi.txt

------------------
- YellowKard -

[This message has been edited by YellowKard (edited April 26, 2000).]
Quote Reply
Re: Error with my script... In reply to
On line 27, you're missing a comma at the end of the line.

I think your other problem is at line 54. Should it be

Code:
print qq|<embed src = "{$FORM{'input'}}" hidden = "true">|;



------------------
JPD






Quote Reply
Re: Error with my script... In reply to
Thanks JPD, I was wondering what the qq|contents| part of
Quote:
print qq|<embed src = "{$FORM{'input'}}" hidden = "true">|;
do?

And... How can you include perl coding in, print <<EndHead; and print <<EndBody; tag? also can it be print <<EndWhatever; ?


My sound on the page isn't loading, and I'm not sure why....

The working script (or should I say not working) can be viewed at http://yellowkard.tentex.com/cgi-bin/jukebox.cgi

The source can be viewed at http://yellowkard.tentex.com/cgi-bin/jukebox.cgi.txt


------------------
- YellowKard -

[This message has been edited by YellowKard (edited April 26, 2000).]
Quote Reply
Re: Error with my script... In reply to
Try putting semi-colons after the following codes:

Code:
EndHdr
EndBody

Like the following:

Code:
EndHdr;
EndBody;

Although I would totally change your codes to look like the following:

Code:
#!c:\usr\bin\perl
# Made by SlashC and YellowKard

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /;

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; }

%sounds = ( "Test Song", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/Bh_mu13.mid",
"Test 2", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/bustamove.mid",
"2", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/dbtgt.mid",
"3", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/dbz.mid",
"4", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/dbz2.mp2",
"5", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/dbz2bsgt.mid",
"6", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/dbz2bvt.mid",
"7", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/dbz3video.mid",
"8", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/Dn64ic.mid",
"9", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/grim1.mid",
"10", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/grim2.mid",
"11", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/grim3.mid",
"12", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/mission.mid",
"13", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/mm8fight.mid",
"14", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/mmend.mid",
"15", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/pmtheme.mid",
"16", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/pokemontheme.mid",
"17", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/Search.mid",
"18", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/waver1.mid",
"19", "http://geocities.yahoo.com/TimesSquare/Corridor/5175/music/zelda1.mid",
"20", "http://www.geocities.com/SiliconValley/Port/9799/music/3-07.mid",
"21", "http://www.geocities.com/SiliconValley/Port/9799/music/4-08.mid",
"22", "http://www.geocities.com/SiliconValley/Port/9799/music/4-08.mid", );

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

print qq|<html>
<HEAD>
<TITLE>-=SlashC's JukeBox=-</TITLE>
</HEAD>
<bgsound src="$FORM{input}" loop="-1">
<BODY bgcolor = "#FFFFFF" text = "#ADFF2F" background="http://www.geocities.com/TimesSquare/Corridor/5175/pics/stars.jpg" link="#0000FF" vlink ="#800080">
<center>
`~SlashC's Cool Juke Box~`
<br>
<form name="input" action="http://yellowkard.tentex.com/cgi-bin/jukebox.cgi" method="POST">
<table align="center"border="3"cellspacing="0"cellpadding="1">
<tr><td>
<select name = "input" size="1" >
|;

foreach $i ( keys %sounds) {
if ($sounds{$i} eq $FORM{input}) {
print qq|<option selected value=\"$sounds{$i}\">$i<\/option\>\n|;
}
else {
print qq|\<option value\=\"$sounds{$i}\"\>$i\<\/option\>\n|;
}
}

print qq|
</select></td></tr></table>
<center>
<INPUT TYPE="image" SRC="http://www.geocities.com/slashc/pics/jukebox.jpg" HEIGHT="24" WIDTH="129" BORDER=0 ALT="Click to Play!">
</center>
</form><table><tr><td><center>
<a HREF ONCLICK="window.close();return false;">
<img SRC="http://yellowkard.tentex.com/wacenter/images/closebutton.gif" BORDER="0" ALT="Close Window" width="96" height="19">
</td></tr></table>
</body></html>
|;

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: Error with my script... In reply to
Ok, I updated the script with what you told me to eliot and the music still doesn't load, I noticed that it writes the html correctly it just doesn't play the song, if you hit the back button then foward it will work... How do I fix this?

------------------
- YellowKard -

Quote Reply
Re: Error with my script... In reply to
I am not too familar with sound files...but the problem could be with the loop command...Why do you have it set to -1???

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: Error with my script... In reply to
The value of -1 in loop, is how you tell it to loop infinate times. When I copied and paste the html from the display of this cgi script it played the sound, its just that somthing the cgi script is doing is like its reading the script then just not looking for stuff in the head.

------------------
- YellowKard -

Quote Reply
Re: Error with my script... In reply to
Try this.

Change:
loop="-1"

to:
loop="infinite"


Dan Smile
Quote Reply
Re: Error with my script... In reply to
Well, what you could try is move the following codes:

Code:
<bgsound src="$FORM{input}" loop="-1">

back above the closing head anchor tag. So, the codes would look like:

Code:
<bgsound src="$FORM{input}" loop="-1">
</HEAD>

Although this looks funny to me.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: Error with my script... In reply to
Thanks for the advice Dan but, the problem isn't with the html that it prints out, the html part is all right its just that something in the cgi script is preventing from it going back and loading what it printed out. Sounds kind of confusing but if you go to the running script and click veiw source you will see what I mean.

------------------
- YellowKard -

Quote Reply
Re: Error with my script... In reply to
Is it not the purpose of the script to output the sound file in a script-generated page with the sound file embedded using bgsound? If the case, I downloaded the source (one sample page) and tested it. No background sound with loop=-1 but it works with loop=infinite.

BTW, some of the files come up 404.


Dan Smile
Quote Reply
Re: Error with my script... In reply to
Im sad to say, neither of those methods worked.

------------------
- YellowKard -

Quote Reply
Re: Error with my script... In reply to
The problem is probably due to you using Netscape. The bgsound tag does not not work with Netscape. For the benefit of MSIE browsers, change -1 to infinity. Then for the benefit of Netscape (and related browsers), add this above the bgsound line:

<SCRIPT LANGUAGE="JavaScript">
<!--
if(navigator.userAgent.indexOf("MSIE") != -1)
document.writeln ('');
else
document.writeln ('<EMBED SRC="mid_file" AUTOSTART="true" HIDDEN="true">');
//-->
</SCRIPT>


Dan Smile
Quote Reply
Re: Error with my script... In reply to
... I don't use netscape, I use IE 5.5
------------------
- YellowKard -



[This message has been edited by YellowKard (edited April 27, 2000).]
Quote Reply
Re: Error with my script... In reply to
I myself use MSIE 5.0 and when I changed -1 to infinite, the music loaded into the background just fine. Why it is not for MSIE 5.5, I don't know. But it seems to be a browser issue or issue specific to your computer setup.

Do you hear music when you go to:
http://geocities.yahoo.com/...5175/music/mmend.mid


Dan Smile
Quote Reply
Re: Error with my script... In reply to
I already stated above that, if you copy and run the printed html sepratly it will work, try it using -1 you will get the same results because what the cgi prints isn't the problem its somthing about its not loading it because it already passed through it once then it prints the html (if this makes any since at all)

------------------
- YellowKard -

Quote Reply
Re: Error with my script... In reply to
It looks like you are completely ignoring dan's suggestion. I think his solution is the answer. Why don't you try his suggestion?

Wink

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: Error with my script... In reply to
Actually I was wrong as I misinterpreted the problem. I believe the problem is related to a content-type header conflict in the dynamically created page. Solution?

One quick fix is to have a link to the mid file. For example, change current Play button to Select. Then beside that insert Play button which is hyperlinked to the mid file. Or better yet, use javascript and HTML. Have you checked out http://www.cgi-resources.com/ or http://www.javascripts.com/ ? I found some rather clever solutions - search on 'juke'.


Dan Smile
Quote Reply
Re: Error with my script... In reply to
Quote:
It looks like you are completely ignoring dan's suggestion. [/qoute]
I tried that before I came to the message board. I should have said that.

I'll look at some of the other scripts made Dan and see how then did it, thanks.

------------------
- YellowKard -