Gossamer Forum
Home : General : Perl Programming :

Wild cards in perl

Quote Reply
Wild cards in perl
I am trying to write a short script that will pull from another web page hosted on a different server a list of game servers that our online. I have been able to grab the page and pull out some of the data out but I seem to be pulling alot of garbage out of the page that I do not want. I use this line after reading in the web page to pull the data I want out

($title) = $_ =~ /\<A HREF="df2dinfo1_cus.htm(.*)\<\/A\>/;

this should pull out the href tag for the url of the online game server listed on the webpage. The format of href tag on the web page is

<A HREF="df2dinfo1_cus.htm?NK=ejffechnneffnUXmjojpU&CK=">NAME OF GAME </A>

The "NAME OF GAME" is what I am trying to pull out but because of the NK= part and the line of letters after it I need to do a wild card search (the letters are a reference number that changes for earch server chreated) but I am unsure on how to do this could some one point me in the right direction.

Quote Reply
Re: Wild cards in perl In reply to
In Reply To:
($title) = $_ =~ /\<A HREF="df2dinfo1_cus.htm(.*)\<\/A\>/;
That regex is wrong. It's matching everything after .htm until the last </A> and putting it in $title. I think what you want is:

($title) = $_ =~ m,<A HREF="df2dinfo1_cus.htm(?:[^"]*)">([^>]+)</A>,;

What that says is:

(?:[^"]*)

0 or more non quotes. The ?: means don't capture it.

([^>]+)

1 or more non >. It will store that in $title.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Wild cards in perl In reply to
Wow worked first time thank you Alex ;-) very much and thank you for explaining it to me I will now read up on "regex" as did not know the technical name of the
fuction of perl I was using so I was a bit lost.

One funny thing I do see in the out put is lost of empty tags I will expain


After reading in the remote web page and pulling out the info I want
print out the parts that I want with and build up a simple webpage.
here is the part that prints out the list of servers

print "<p>$title</p>";


what I see in the html out put is some thing like this.


<p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>USA Warrior-T1 </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>KeG PaRtY </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>Het - The Pass </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>THE TRENCHS </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>SNAKE PIT </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>NOVA OFFICIAL </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>NOVA OFFICIAL3 </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>NOVA OFFICIAL2 </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>N!TRo*DC* </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>SOH KOD </p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p>



As you can see quite a mess I guess I could run the server list through a cleaning method.

if ($title eq"") {
null
}
else {

print "<p>$title</p>";
}

Is that the best method to do a clean up ? or should I be looking some where else ?



Quote Reply
Re: Wild cards in perl In reply to
<edit> oops, NM. I didn't read the first post that well :)</edit>

Regards,
Charlie