Toon posts:

[perl]Loop breaken, hoe moet dat?

Pagina: 1
Acties:
  • 120 views sinds 30-01-2008
  • Reageer

Verwijderd

Topicstarter
Hallo allemaal,
ik zit weer is met een probleem, ik heb dit script (intellilink zelf een beetje gemod):

----------------------------------------------
#!/usr/bin/perl

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

require "variables.cgi";
$sitename = "$variables{'sitename'}";
$cgiurl = "$variables{'cgiurl'}";
$body = "$variables{'body'}";
$standout1 = "$variables{'standout1'}";
$standout2 = "$variables{'standout2'}";
$body = "$variables{'body'}";
$signup = "$variables{'signup'}";
$displaymult = "$variables{'displaymult'}";
$mintoshow = "$variables{'mintoshow'}";

$buffer = $ENV{'QUERY_STRING'};
@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;
$value =~ s/~!/ ~!/g;
$in{$name} = $value;
}
$start = $in{'start'};
$end = $in{'end'};
$min = $in{'min'};
##########################
##
#
if($start eq "") {
# you can change this number if you want...
$start = 1;
}
if($end eq "") {
# you can change this number if you want...
$end = 15;
}
if($start2 eq "") {
# you can change this number if you want...
$start2 = 1;
}
if($end2 eq "") {
# you can change this number if you want...
$end2 = 15;
}
if($min eq "") { $min = $mintoshow; }
#
##
##########################
# Don't mess with anything below this.

{
open(DATA,"top.txt");
print <DATA>;
close(DATA);
print <<EOF;
EOF
}
print "<table width=\"100%\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"1\">\n";
print "<tr><td><i><center><a href=\"http://www.point-warez2.f2s.com/cgi-bin/intellilink/intellilink2.cgi\" target=\"_parent\">More links</a></center></i></tr></td>\n";
print "<tr><td><i><center><a href=\"http://www.point-warez2.f2s.com/cgi-bin/intellilink/addlink.cgi\" target=\"_parent\">Submit link</a></center></i></tr></td>\n";
print "<tr><td><i><center><a href=\"http://www.point-warez2.f2s.com/cgi-bin/intellilink/edit.cgi\" target=\"_parent\">Edit acount</a></center></i></tr></td>\n";
open(DATA,"intellilink/data.txt");
flock (DATA,2);
@data = <DATA>;
flock (DATA,8);
close(DATA);
@data = sort {$b <=> $a} @data;
foreach $line(@data) {
$counter++;
@linedata = split (/\|/, $line);
if(($counter >= $start)&&($linedata[0] >= $min)) {
if((($linedata[0]*$displaymult) > $linedata[1])||($linedata[1] eq 0)) {
$begun = "1";
if($linedata[0] > $linedata[1]) { print "$standout1"; }
print "<tr><td>$counter. <a href=\"$cgiurl/out.cgi?id=$linedata[2]\" onmouseover=\"window.status='In:$linedata[0] Out:$linedata[1] Description: $linedata[5]';return true\" onmouseout=\"window.status=''; return true\" target=\"_blank\">$linedata[4]</a></td></tr>\n";
if($linedata[0] > $linedata[1]) { print "$standout2"; }
} else { $counter--; }
}
else {
if(($signup eq "1")&&($begun ne "")) { print "<tr><td>$counter. <a href=\"$cgiurl/addlink.cgi\" target=\"_parent\">Your site?</a></td></tr>\n"; }
}
if($counter eq $end) { ; }
}
print "</table><br><br>\n";
{
open(DATA,"1.txt");
print <DATA>;
close(DATA);
print <<EOF;
EOF
}
print "<table width=\"100%\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"1\">\n";
print "<tr><td><i><center><a href=\"http://www.point-warez2.f2s.com/cgi-bin/intellilink/intellilink2.cgi\" target=\"_parent\">More links</a></center></i></tr></td>\n";
print "<tr><td><i><center><a href=\"http://www.point-warez2.f2s.com/cgi-bin/intellilink/addlink.cgi\" target=\"_parent\">Submit link</a></center></i></tr></td>\n";
print "<tr><td><i><center><a href=\"http://www.point-warez2.f2s.com/cgi-bin/intellilink/edit.cgi\" target=\"_parent\">Edit acount</a></center></i></tr></td>\n";
open(DATA,"appz/data.txt");
flock (DATA,2);
@data = <DATA>;
flock (DATA,8);
close(DATA);
@data = sort {$b <=> $a} @data;
foreach $line(@data) {
$counter2++;
@linedata = split (/\|/, $line);
if(($counter2 >= $start2)&&($linedata[0] >= $min)) {
if((($linedata[0]*$displaymult) > $linedata[1])||($linedata[1] eq 0)) {
$begun = "1";
if($linedata[0] > $linedata[1]) { print "$standout1"; }
print "<tr><td>$counter2. <a href=\"$cgiurl/out.cgi?id=$linedata[2]\" onmouseover=\"window.status='In:$linedata[0] Out:$linedata[1] Description: $linedata[5]';return true\" onmouseout=\"window.status=''; return true\" target=\"_blank\">$linedata[4]</a></td></tr>\n";
if($linedata[0] > $linedata[1]) { print "$standout2"; }
} else { $counter2--; }
}
else {
if(($signup eq "1")&&($begun ne "")) { print "<tr><td>$counter2. <a href=\"$cgiurl/addlink.cgi\" target=\"_parent\">Your site?</a></td></tr>\n"; }

}

if($counter2 eq $end2) { ; }
}
print "</table><br><br>\n";
{
open(DATA,"bottom.txt");
print <DATA>;
close(DATA);
print <<EOF;
EOF
exit;
}
----------------------------------------------

Nou zit ik met een probleem, als ik dit script aanroep dan toont hij alle links in de database en dat is niet de bedoeling.... zoals je ziet heb ik netjes aangegeven hoeveel links er gedisplayd moeten worden.

Als ik nou in plaatst van :
if($counter2 eq $end2) { ; }
er dit van maak
if($counter2 eq $end2) { exit; }
dan krijg ik wel 15 links gedisplayd maar dan werkt het de rest van het script niet meer.

Wie kan mij vertellen hoe dit moet? Dus zodat er in elke intellilink maar 12 links gedisplayd wordt?

Ik hoop dat het in hemels naam mogelijk is :)

met vriendelijke greetzz erik

  • ACM
  • Registratie: Januari 2000
  • Niet online

ACM

Software Architect

Werkt hier

Ik heb je topictitel maar wat duidelijker gemaakt.

Daarnaast verzoek ik je je code tussen [code]-tags te plaatsen voor een beter overzicht.
En is het wellicht handig uit te zoeken of perl het break statement kent voor for/while loops.

Of werk met goto

Verwijderd

Topicstarter
Op zondag 09 december 2001 13:05 schreef ACM het volgende:
Ik heb je topictitel maar wat duidelijker gemaakt.

Daarnaast verzoek ik je je code tussen [code]-tags te plaatsen voor een beter overzicht.
En is het wellicht handig uit te zoeken of perl het break statement kent voor for/while loops.

Of werk met goto
eeum :? hoe bedoel je dat... sorry ik ben nog een beetje newbie in de perl... kun je me een voorbeeld geven?

Verwijderd

last LABEL
last The "last" command is like the "break" statement
in C (as used in loops); it immediately exits the
loop in question. If the LABEL is omitted, the
command refers to the innermost enclosing loop.
The "continue" block, if any, is not executed:

LINE: while (<STDIN>) {
last LINE if /^$/; # exit when done with header
#...
}

"last" cannot be used to exit a block which
returns a value such as "eval {}", "sub {}" or "do
{}", and should not be used to exit a grep() or
map() operation.

Note that a block by itself is semantically
identical to a loop that executes once. Thus
"last" can be used to effect an early exit out of
such a block.

See also the continue entry elsewhere in this
document for an illustration of how "last",
"next", and "redo" work.
perldoc -f last.