####################################################################################### #-- This PERL script creates a 114-GIG Flat File containing 233+ million Bible verses, #-- for 7500 complete copies of the KJV Bible (31,102 verses/copy). #-- #-- One copy of the Bible is used as input, and is of variable-length record format, #-- with CR/LF (newline) record terminator. Output file will be formatted to 528 byte #-- fixed-length records, with no record terminator. #-- #-- Fixed-length records are used to demonstrate capacity requirements for a READ/WRITE #-- database where the records are edited in-place at reliable byte offset locations. #-- #-- A similar READ ONLY database with variable-length records would have the capacity #-- to hold 4 times as many Bible verses i.e. almost 1 Billion records/verses. #-- #-- This Flat File is being created for RANDOM ACCESS of its records, where the byte #-- offset locations are stored persistently in a PERL SDBM database file of key/value #-- pairs tied to an in-memory PERL program hash table at run-time. #-- #-- Tested on Windows 7 Home Premium with NT File System (NTFS). #-- Tested with ActiveState ActivePerl for Windows version/release 5.26.1 #-- Tested using unbuffered File I/O syntax: sysopen, sysseek, sysread, syswrite, #-- and close. ####################################################################################### use File::Basename; use Fcntl; $cwd=dirname($0); #-- this application program directory print "Processing... Please wait..." . "\n"; $total_verses = 0; @nbr_verses = (); open(IN, "< $cwd\\BibleVerses1Copy.txt") or do {print "Error on open input: $!\n"; sleep 5; die}; while () { chomp; #-- remove CR/LF push @nbr_verses, $_; #-- load 31,102 verses to an array in memory } sysopen(OUT,"$cwd\\KJV_BIBLE_SDBM_528_31102_7500.dat", O_WRONLY|O_CREAT) or do {print "Error on open output: $!\n"; sleep 5; die}; $tell = sysseek(OUT, 0, 0); #-- top of file for ($tran_nbr=1; $tran_nbr<=7500; $tran_nbr++) { print "$tran_nbr of 7500\n"; foreach $verse (@nbr_verses) { $total_verses++; $line=sprintf("%-528s", $verse); syswrite(OUT, $line); } } print "Total verses written = $total_verses \n"; exit; END { close(IN); close(OUT); sleep 5; }