Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Searching a whole directory of databases

by drewboy (Sexton)
on Jun 23, 2002 at 09:50 UTC ( #176578=perlquestion: print w/replies, xml ) Need Help??

drewboy has asked for the wisdom of the Perl Monks concerning the following question:

I have one search script (written in perl) that's designed to search only one database:

open (DB, "<database.db")

However, now I'm spidering websites and assigns one database for each site (all in .txt format) (i.e. cnn.txt, aol.txt, mtv.txt, yahoo.txt) All files are saved in a folder called "searchdbs". I wonder if it would be possible for my script to just look into the searchdbs folder and open each database inside of it rather than tweaking my script each time I spider a new website. Looking forward to your help... Thanks as always...:-)

Replies are listed 'Best First'.
Re: Searching a whole directory of databases
by crazyinsomniac (Prior) on Jun 23, 2002 at 10:15 UTC
Re: Searching a whole directory of databases
by mfriedman (Monk) on Jun 23, 2002 at 10:05 UTC
Re: Searching a whole directory of databases
by pjf (Curate) on Jun 24, 2002 at 03:01 UTC
    You might find the following skeleton useful. This assumes you're already in the searchdbs folder.
    foreach my $file (<*.txt>) { open(FILE,"< $file") or die "Cannot open $file - $!\n"; # Read in from FILE and do stuff with it... }
    Of course, There's More Than One Way To Do It. You might find it easier dropping all the filenames in @ARGV and then using Perl's magic diamond operator:
    @ARGV = <*.txt>; while (<>) { # Files will now be opened and read automagically, and # each line placed in $_. You can see which file # you're currently reading from by looking at $ARGV. }
    Understanding how the above works is left as an exercise for the reader. ;)

    All the best,
    Paul Fenwick
    Perl Training Australia

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://176578]
Approved by wil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2023-02-03 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (30 votes). Check out past polls.

    Notices?