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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 02-24-2005, 04:43 PM   #1
gezzed
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?
gezzed is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-24-2005, 04:50 PM   #2
mortenb
Confirmed User
 
mortenb's Avatar
 
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..
mortenb is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-24-2005, 04:52 PM   #3
gezzed
Confirmed User
 
Join Date: Mar 2002
Posts: 317
Quote:
Originally Posted by mortenb
The simplest solution would be to stop using a txt file and throw the data in a db..
I've always been a fan of minimalism. I suppose that if there is no other way I'll look into using SQL. But I'd like believe there is a way around this problem that doesn't complicate matters further.
gezzed is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-24-2005, 05:07 PM   #4
NetRodent
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
NetRodent is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-24-2005, 05:08 PM   #5
Tom_PM
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.
Tom_PM is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-24-2005, 05:20 PM   #6
gezzed
Confirmed User
 
Join Date: Mar 2002
Posts: 317
Quote:
Originally Posted by PR_Tom
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.
Thanks Tom, I'll have a look into it.
gezzed is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-24-2005, 05:51 PM   #7
gezzed
Confirmed User
 
Join Date: Mar 2002
Posts: 317
Looks like grep is the answer. Thanks again Tom.
gezzed is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-24-2005, 05:54 PM   #8
sonofsam
Too lazy to set a custom title
 
Join Date: Dec 2004
Location: Vancouver
Posts: 18,638


sorry
__________________
I like turtles.
sonofsam is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-24-2005, 06:01 PM   #9
swedguy
Confirmed User
 
Industry Role:
Join Date: Jan 2002
Posts: 7,981
Is the xxx,yyy,zzz a set length (like always 3 chars long)?
swedguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-24-2005, 06:02 PM   #10
MrJackMeHoff
Confirmed User
 
Join Date: Mar 2004
Location: LOLLIPOP ISLAND =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-= =-=-=-=-=-=-=-=-=-=-=
Posts: 4,569
Using a %hash you could search 50k text file easy
__________________
MrJackMeHoff is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-25-2005, 06:22 AM   #11
teksonline
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
teksonline is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.