Hejsan!
Jag behöver lite hjälp med detta:
Jag har ett script som ser ut så här:
#!/usr/local/bin/perl
sub main {
open(FILE, $file_id) or die("Error! Can't open $file_id");
@lines = <FILE>;
close(FILE);
print "Content-type: text/html\n\n";
$i=0;
$flag=0;
foreach $line (@lines) {
($id, @temp) = split(/\|/, $line);
$id =~ s/\s//g; # Remove spaces in the $id
if ($ENV{'QUERY_STRING'} eq $id) {
$index = $i;
$flag = 1;
@paths = @temp;
}
$i++;
}
if ($flag == 0) {
&Invalid_id; # ID not found in database
}
else {
&Show_page; # Show download page
}
exit;
}
sub Invalid_id {
####################################### #
# Edit the following if you want to have a different error page#
# #######################################
print <<END_OF_HTML;
<html>
<head>
<title>Invalid ID</title>
</head>
<body bgcolor="#353E8D" text="#ffffff">
<font face="Verdana" size=4><b>Invalid ID</b></font>
<hr size="1" width="90%" align="left">
<p>
<font face="Verdana" size=2>
ID not found in database
</font>
</body>
</html>
END_OF_HTML
}
sub Show_page {
open(DESC, $file_desc) or die("Error! Can't open $file_desc");
@lines = <DESC>;
close(DESC);
($title, $desc) = split(/\|/, $lines[$index]);
open(INFO, $file_info) or die("Error! Can't open $file_info");
@lines = <INFO>;
close(INFO);
$info = $lines[$index];
$i=0;
$links = "";
foreach $path (@paths) {
chomp($path);
if ($path !~ /^(http\:\/\/|ftp\:\/\/)/i) {
$temp = $baseurl;
$temp =~ s/^(http\:\/\/|ftp\:\/\/)(.+)/$2/;
$server = $temp;
$link = $baseurl.$path;
}
else {
$temp = $path;
$temp =~ s/^(http\:\/\/|ftp\:\/\/)(.+)(\/.*)/\2/;
($server, $null) = split(/\//, $temp);
$link = $path;
}
$temp = $link_html;
$temp =~ s/\[\%\%LINK\%\%\]/$link/gi;
$temp =~ s/\[\%\%SERVER\%\%\]/$server/gi;
$links = $links.$temp;
$i++;
}
open(HTML, $html_temp) or die("Error! Can't open $html_temp");
@lines = <HTML>;
close(HTML);
foreach $line (@lines) {
if ($line =~ /\[\%\%TITLE\%\%\]/i) {
$line =~ s/\[\%\%TITLE\%\%\]/$title/gi;
}
if ($line =~ /\[\%\%DESC\%\%\]/i) {
$line =~ s/\[\%\%DESC\%\%\]/$desc/gi;
}
if ($line =~ /\[\%\%FILESIZE\%\%\]/i) {
if ($paths[0] !~ /^(http\:\/\/|ftp\:\/\/)/i) {
$filename = $basedir.$paths[0];
chomp($filename);
@filestat = stat($filename);
$line =~ s/\[\%\%FILESIZE\%\%\]/$filestat[7]/gi;
}
else {
$line =~ s/\[\%\%FILESIZE\%\%\]//gi;
}
}
if ($line =~ /\[\%\%LINKS\%\%\]/i) {
$line =~ s/\[\%\%LINKS\%\%\]/$links/gi;
}
if ($line =~ /\[\%\%INFO\%\%\]/i) {
$line =~ s/\[\%\%INFO\%\%\]/$info/gi;
}
print $line
}
}
return 1;
Jag får sedan felmeddelandet:
Can't return outside a subroutine at d:\clients\sks.nu\scripts\id\DLTempex.pl line 145.
Rad 145 är alltså den sista raden i scriptet. Nån som har någon aning om vad som är fel på sista raden?
------------------
//
<title>Hazze</title>