![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Mar 2002
Posts: 317
|
Any perl people in the house?
I'm trying to develop a script that searches through a simple .txt file and returns all the records matching a search query.
This is the general format of the .txt file xxx----somecategory----123Mb yyy----someothercategory----456Mb zzz----onemorecategory---789Mb Then, someone specifies a query through my site and I need to check whether any of the records in the .txt file match the query by scanning through the xxx, yyy, zzz parts. Here's the snag, I have 50,000 entries in the .txt file so a simple foreach loop takes way too long. Any ideas? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Jul 2004
Location: Denmark ICQ: 7880009
Posts: 2,203
|
The simplest solution would be to stop using a txt file and throw the data in a db..
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 | |
Confirmed User
Join Date: Mar 2002
Posts: 317
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Join Date: Jan 2002
Location: In the walls of your house.
Posts: 3,985
|
[QUOTE=gezzed]Here's the snag, I have 50,000 entries in the .txt file so a simple foreach loop takes way too long./QUOTE]
Its not the foreach that's taking the time. Its the pattern matching on 50,000 entries. The easiest way would be with a database, properly indexed. If you're stuck on storing your data in text files, you could create a new set of textfiles to index what's in the main text file.
__________________
"Every normal man must be tempted, at times, to spit on his hands, hoist the black flag, and begin slitting throats." --H.L. Mencken |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Porn Meister
Industry Role:
Join Date: Feb 2005
Posts: 16,443
|
Probably with grep. It's inherently line-based and fast with regex. I dont have a sample, but that should get you on the right path I think.
__________________
43-922-863 Shut up and play your guitar. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 | |
Confirmed User
Join Date: Mar 2002
Posts: 317
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: Mar 2002
Posts: 317
|
Looks like grep is the answer. Thanks again Tom.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Too lazy to set a custom title
Join Date: Dec 2004
Location: Vancouver
Posts: 18,638
|
![]() sorry ![]()
__________________
I like turtles. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Industry Role:
Join Date: Jan 2002
Posts: 7,981
|
Is the xxx,yyy,zzz a set length (like always 3 chars long)?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Join Date: Mar 2004
Location: LOLLIPOP ISLAND =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-=
Posts: 4,569
|
Using a %hash you could search 50k text file easy
__________________
![]() ![]() ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
So Fucking Banned
Join Date: Jan 2005
Location: At My Desk
Posts: 2,904
|
use regular expressions
hit me up if you want on aim freebsdteks |
![]() |
![]() ![]() ![]() ![]() ![]() |