CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Opening Hundreds Of Data Bases

 



perlkid
stranger

Sep 12, 2000, 7:17 PM

Post #1 of 5 (358 views)
Opening Hundreds Of Data Bases Can't Post

 Hello Everyone,

First Off,

I talking about flat file data bases.

I have a folder with about 900 data bases in it. Periodicaly each data base needs to be filtered for duplicates. Thanks to kanji I have a great duplicate checker Smile. How can I open each one of the data bases and filter them for duplicates, then print the filtered information back to the data bases.

I thought maybe doing a foreach loop to open them all, but how would I read the files into unique arrays so that the same information will be printed back.

Will perl allow something like this?
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


foreach $file (@file_list)
{
$c++;
open($c, "<$file");
@file$c=<$c>;
close($c);
}
</pre><HR></BLOCKQUOTE>
Thanks,

perlkid


Kanji
User

Sep 12, 2000, 8:01 PM

Post #2 of 5 (358 views)
Re: Opening Hundreds Of Data Bases [In reply to] Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

my $db_dir = "/path/to/flat/file/DBs";


chdir $db_dir or die " chdir($db_dir): $!";
opendir DB, $db_dir or die "opendir($db_dir): $!";


DB: while ( my $db = readdir(DB) ) {
next DB unless $db =~ /\.db$/ # ... is a db file
&& -s $db; # ... isn't empty


# Do an in-place edit. Change "" to something else
# if you want to keep backups or your OS doesn't
# allow $^I to be empty.
local ( $^I, @ARGV ) = ( "", $db );
my %dupe;


while ( <> ) {
# Ignore the line if we've
# already seen it
print unless $dupe{$_}++;
}
}</pre><HR></BLOCKQUOTE>


Kanji
User

Sep 12, 2000, 8:10 PM

Post #3 of 5 (358 views)
Re: Opening Hundreds Of Data Bases [In reply to] Can't Post

You weren't far off: @{ "file_$c" } = <$c>; would have created @file_1, @file_2, etc.

IMHO, that's both ugly and silly when you can employ an array of arrays instead ($file[$c] = [ <$c> ]; to build the arrays, and @{ $file[$c] } to read them).

Regardless, no need to go to the trouble of either method when you can do in-place edits as shown in my post above. ;)


Kanji
User

Sep 14, 2000, 3:40 AM

Post #4 of 5 (358 views)
Re: Opening Hundreds Of Data Bases [In reply to] Can't Post

I've come close to asking questions on a few occassion, but always thought up a solution just before hitting POST. Wink


perlkid
stranger

Sep 14, 2000, 10:03 AM

Post #5 of 5 (358 views)
Re: Opening Hundreds Of Data Bases [In reply to] Can't Post

 
Thanks A Lot Kanji,

I was going to wait and post when I used the code, But unfortunatly I've been tied up with banner scripts all day, Frown

I'll post again when I get it working, As Soon As Possible.

Thanks Again,

perlkid

P.S. When Are you ever going to ask a question? He he,

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives