Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem writing/reading to text file 1

Status
Not open for further replies.

JASONE25

Technical User
Jun 23, 2005
54
NL
He experts. I wrote this script but unfortunely when i run it i get the following erro. I am passing this script the number of songs as linke below:


the script supposed to write it to text file and play it but unfortunely it does. could any expert help me fix this error.i put permition for it as read and write but still does not work!Thanks
Code:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


Can't open songlist.txt at c:\inetpub\[URL unfurl="true"]wwwroot\cgi-bin2\textchat\multsong.pl[/URL] line 145.




Code:
#!/usr/bin/perl

 
SWITCH:
{

@pairs = split(/&/, $ENV{"QUERY_STRING"});

foreach $pair (@pairs) {
 ($name, $value) = split (/=/, $pair);
 $formData{"$name"} = $value;
}

$fname = $formData{name};

if( $fname eq "ID1" )
{
$fname="[URL unfurl="true"]http://localhost/songs/g1.rm";[/URL]
   last SWITCH;
}
if($fname eq "ID2")
{
$fname="[URL unfurl="true"]http://localhost/songs/g2.rm";[/URL]
last SWITCH;
      
}

if($fname eq "ID3")
{
$fname="[URL unfurl="true"]http://localhost/songs/g3.rm";[/URL]
last SWITCH;
      
}
if($fname eq "ID4")
{
$fname="[URL unfurl="true"]http://localhost/songs/g4.rm";[/URL]
last SWITCH;
      
}
DEFAULT:
{
$fname="[URL unfurl="true"]http://localhost/salma/m7.rm";[/URL]
last SWITCH;
}
}#END OF SWITCH BLOCK




$outfile= 'songlist.txt';
open(OUTPUT, ">$outfile")or die "Can't open $outfile";

close(OUTPUT);


#################################################################################
#Defult Subroutines
 


print <<method;

<html>
<head>
        <title>Voice Music</title>
</head>

<script language=JavaScript src="[URL unfurl="true"]http://localhost/dll.js">[/URL]
</script>


<body bgColor=#336699 leftmargin="0" topmargin="0">

#Real Audio Applet
<OBJECT ID=video1 CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" HEIGHT=60 WIDTH=285>
<PARAM NAME="controls" VALUE="ControlPanel,StatusBar">
<PARAM NAME="console" VALUE="Clip1">
<PARAM NAME="autostart" VALUE="true">
<PARAM NAME="src" VALUE="[URL unfurl="true"]http://localhost/cgi-bin2/songlist.txt">[/URL]
<EMBED SRC="$fname" type="audio/x-pn-realaudio-plugin" CONSOLE="Clip1" CONTROLS="ControlPanel,StatusBar" HEIGHT=60 WIDTH=285 AUTOSTART=true>
</OBJECT>

</body>

</html>

method
 
Guys: no-one's solved the original problem yet - the script isn't outputting any http headers. That problem is masked as long as the script has other errors because CGI:Carp puts appropriate headers on it's error messages.

This
Code:
print <<METHOD;

<html>
<head>
        <title>Voice Music</title>
should look something more like
Code:
print <<METHOD;
Content-Type: text/html; charset=ISO-8859-1

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html>
<head>
        <title>Voice Music</title>
but I'd be tempted to "use CGI;" and rewrite the whole print as
Code:
use CGI qw/ :standard *Param /;

print header,
    start_html(
        -title=>'Voice Music',
        -script=>{ -src=>'[URL unfurl="true"]http://localhost/dll.js'[/URL] },
        -style=>{ -code=>q~
             body {
               background-color: #336699;
               margin-left: 0px;
               margin-top: 0px;
             }
          ~ }
    ),
    comment('Real Audio Applet'),
    object( { -id=>'video1',
              -classid=>'clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
              -height=>60, -width=>285,
        },
        Param({ -name=>'controls',
                -value=>'ControlPanel,StatusBar'}),
        Param({ -name=>'console', -value=>'Clip1'}),
        Param({ -name=>'autostart', -value=>'true'}),
        Param({ -name=>'src',
                -value=>'[URL unfurl="true"]http://localhost/cgi-bin2/songlist.txt'}),[/URL]
        embed( { -src=>$startName,
                 -type=>'audio/x-pn-realaudio-plugin"',
                 -console=>'Clip1"',
                 -controls=>'ControlPanel,StatusBar',
                 -height=>6,
                 -width=>285,
                 -autostart=>'true',
              } ),
     ),
    end_html;

for a huge number of reasons.

f

&quot;As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilkes
 
That'll be
Code:
   print OUTPUT $songs{$name} .'\n';
Things like \n only work in double-quoted strings. Use
Code:
   print OUTPUT "$songs{$name}\n";
and you'll be fine.

fish

&quot;As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilkes
 
Thanks now it writes the 2 songs url to text file but it only plays the first one . After first one finishes it does not play the next one!! Is there a way to fix this ?Thanks
 
Probably need an extra param for the real audio object but I'm afraid can't help you - I'm alergic to reality. You could maybe try searching all forums for "real audio" and see whether there is help available.

f

&quot;As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilkes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top