...

View Full Version : what's the difference?



FJbrian
06-19-2002, 12:24 AM
foreach $line (@lines) {
if ($line =~ /\<li([^]+)([^<]+)/) {
if ($line =~ /\<li\>\<a href\=\"([^\"]+)\">([^<]+)<\/a>/) {
if ($FORM{'url'} eq $1) {
&repeat_url;
}
$i++;
}
}
The second line is my goof
everything else is taken from a script that works
I've removed everything regarding links (a href) from a script except for this line
yes I'm, fudging an old script cuz I don't have a clue:o

I need it to go to the repeat url function if the variable url matches something already on the page
I tried to cut out the a href=" stuff (from line 3)but it appears I goofed
Anyone fix line 2 for me?

Calilo
06-19-2002, 03:42 AM
Line two appears to be fine i dont know what you want exactly, what do you mean with , something already on the page. you arnt giving any value to the url variable,

could you make it clearer plase?

Calilo

FJbrian
06-19-2002, 03:52 AM
sure
umm...
here
http://www.footballjoint.com/Draft/team1.html
(if ya enter info you'll get a 500 error)
I took Matt's free links script and stripped the (a href) tags out of the script so it won't post values as a link
added in some html table and refresh tags to the html form page and...that's about it
after I removed those, I used an <li>(orderred list) tag as my counter instead of <a href like he did. But I'd swear it's 90-95% the very very same script. The 500 error is solely caused by that line. Everything is kewl otherwise.
And thanks for your time
here's the code:

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@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/<([^>]|\n)*>//g;
$value =~ s/<//g;
$value =~ s/>//g;
$FORM{$name} = $value;
}

if (!($FORM{'title'})) {
&no_title;
}

# Enter our tags and sections into an associative array

%sections = ("team1","TEAM1","team2","TEAM2","team3","TEAM3",
"team4","TEAM4","team5","TEAM5","team6","TEAM6",
"team7","TEAM7","team8","TEAM8","team9","TEAM9",
"team10","TEAM10","team11","TEAM11","team12","TEAM12");

# Suck previous link file into one big string
open(FILE,"$filename");
@lines = <FILE>;
close(FILE);

$i=1;
foreach $line (@lines) {
if ($line =~ /\<li([^]+)([^]+)/) {
if ($FORM{'url'} eq $1) {
&repeat_url;
}
$i++;
}
}

# Open Link File to Output
open (FILE,">$filename");

foreach $line (@lines) { # For every line in our data

if ($line =~ /<!--time-->/) {
@months = ('January','February','March','April','May','June',
'July','August','September','October','November','December');

@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday',
'Friday','Saturday');

($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($mday < 10) { $mday = "0$mday"; }
$year += 1900;
$date = "on $days[$wday], $months[$mon] $mday, $year at $hour:$min:$sec";
print FILE "<!--time--><b>Last player was selected $date</b>Central<hr>\n";
}
elsif ($line =~ /<!--number-->/) {
print FILE "<!--number--><b>There have been <i>$i</i> players selected ";
print FILE "</b><br>\n";
}
else {
print FILE $line;
}

foreach $tag ( keys %sections) { # For every tag
if ( ($FORM{'section'} eq $sections{$tag}) &&
($line =~ /<!--$tag-->/) ) {

print FILE "<li type\"1\">$FORM{'title'} <font color=white><i>$FORM{'url'}</i></font>\n";
}
}
}

close (FILE);

# Return Link File
print "Location: $linksurl\n\n";

if ($database ne '') {
open (DATABASE,">>$database");
print DATABASE "$FORM{'url'}\n";
close(DATABASE);
}

sub no_url {
print "Content-type: text/html\n\n";
print "<html><head><title>ERROR: No Team enterred</title></head>\n";
print "<body bgcolor=#FFFFFF text=#000000><center>";
print "<h1>No Team enterred</h1></center>\n";
print "You forgot to enter the team this player plays for";
print "Your post was invalid.<p>\n";
print "<form method=POST action=\"$linkscgi\">\n";
print "<input type=hidden name=\"title\" value=\"$FORM{'title'}\">\n";
print "<input type=hidden name=\"section\"";
print "value=\"$FORM{'section'}\">\n";
print "Team: <input type=text name=\"url\" size=30><p>\n";
print "<input type=submit> * <input type=reset>\n";
print "<hr>\n";
print "<a href=\"$linksurl\">$linkstitle</a>\n";
print "</form></body></html>\n";

exit;
}

sub no_title {
print "Content-type: text/html\n\n";
print "<html><head><title>ERROR: No Player Selected</title></head>\n";
print "<body bgcolor=#FFFFFF text=#000000><center>";
print "<h1>No Player selected</h1></center>\n";
print "You forgot to enter a player that you wanted";
print "<p>\n";
print "<form method=POST action=\"$linkscgi\">\n";
print "<input type=hidden name=\"url\" value=\"$FORM{'url'}\">\n";
print "<input type=hidden name=\"section\"";
print "value=\"$FORM{'section'}\">\n";
print "Player: <input type=text name=\"title\" size=30><p>\n";
print "<input type=submit> * <input type=reset>\n";
print "<hr>\n";
print "<a href=\"$linksurl\">$linkstitle</a>\n";
print "</form></body></html>\n";

exit;
}

sub repeat_url {
print "Content-type: text/html\n\n";
print "<html><head><title>ERROR: Repeat URL</title></head>\n";
print "<body bgcolor=#FFFFFF text=#000000><center><h1>Repeat URL</h1></center>\n";
print "Sorry, this URL is already in the Free For All Link Page.\n";
print "You cannot add this URL to it again. Sorry.<p>\n";
print "<a href=\"$linksurl\">$linkstitle</a>";
print "</body></html>\n";


exit;
}

Calilo
06-19-2002, 04:39 AM
Seem to be working now, (http://www.footballjoint.com/Draft/team1.html)
and the script looks perfecly ok,h

Calilo

FJbrian
06-19-2002, 04:59 AM
I was playin' that's why there's no 500 error
same prob
please notice on Team 12 there are many of the same values
that is the line of the script I'm referring to
it doesn't match the value and send them to the repeat url function
a repeated value should not be allowed

Calilo
06-19-2002, 05:06 AM
maybe the problems is that the $filename is an empty var, you should add something like this to see if that is the problem

open(FILE,"$filename") || die "couldnt open $filename in read mode";

always make sure to use those die expressions, very very importants ones,

calilo

sir pannels
06-19-2002, 01:53 PM
calilo you missing > or >> in there?:confused

FJbrian
06-19-2002, 04:47 PM
the filename variable is the real long location of the html page like
awholebunchofstuff/public_html/Draft/team1.html
basedir is ...
I didn't post those 4 lines of code nor
/usr/bin/perl
just to be safe

I am 100% certain the problem is that line I mentioned
In the meantime, I wrote someone else with the code and he responded "check line #"...the line I mentioned.
I don't have 200 bucks to pay him to fix that one line.

sir pannels
06-19-2002, 05:09 PM
how you know its that line? if the logs or error is telling you..example its line 30 then most prolly its line 29 amd of ot says 83 its prolly 82 and so forth;)
sir p

FJbrian
06-19-2002, 05:36 PM
How?
I changed it line by line checking every single time to make sure it still worked
that's where I got stuck

this isn't going so well
I guess I'm a bad 'splainer
I don't know PERL
forget that jazz above, try again
I want the script to go to repeat URL function if what's being submitted has already been submitted.

if $FORM{'url'} matches url's in document already
&repeat_url

How's this for wording a question:D

Can you replace my
ENGLISH (matches URL's in document already) with PERL?

amy2go
06-20-2002, 12:46 AM
Decided to give this one a whirl.

Your code:

if ($line =~ /\<li([^]+)([^]+)/) {

should be:

if ($line =~ m/\<li([^]+)([^]+)/) {

Add the m in front of the forward slash. The m stands for match; s stands for substitute, and tr stands for transliteration (or translation). Hope this helps..didn't test it.

-Amy

FJbrian
06-20-2002, 03:27 AM
that didn't work
well the page still posts and functions it just doesn't match up and go to repeat URL function

see
http://www.footballjoint.com/Draft/team1.html
scoobydoo yogibear are on many teams:)
thanks for trying though

amy2go
06-20-2002, 04:48 PM
I'm still new to Perl, but I haven't read a file the way that you have this set up, not to say that it can't be done that way. Here is how I have read a file in one of my Perl scripts - and maybe you can modify it to suit your needs:

open( FILE, "filename.txt") or
die("The file could not be opened");

while($line = <FILE>){
chomp($line);
#code to implement on each line
}

Other than that, maybe you should look at your regular expression: /\<li([^]+)([^]+)/

Minus the two forward slashes, which contain the regexp, you have a backslash, so the < will be taken literally, and the li will be also. That leaves <li
Then you have opening parenthesis ( , which signifies a group. Then you have brackets [] , which says you can have any one of the characters inside.
Then you have caret ^ , which means you're going to examine a string starting at it's beginning.
Then after the brackets you have a plus sign + , which means one or more of whatever the previous item was.
Then you have the closing parenthesis ) of the group.
Then you repeat that group.

Problems with this (that I can see) is:
1. You never closed your <li> tag, as in \>
2. You never specify what character is allowed in the brackets; you only signified a beginning of a string.
3. Usually the caret would be used only once at the beginning of the regexp as soon as you type the forward slash, as in /^

Best of luck,

Amy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum