Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I suggested earlier, DBD::CSV. This is a "full DB" that uses a CSV (Comma Separated Value) file. The advantage of this is that since it uses a "flat" CSV data file, you can easily 1)create the initial DB, 2) watch what happens as you run SQL statements. This module is used like you'd use a massive commercial DB...you connect to the DB, then run SQL on it. It handles multiple processes and deals with all this lock stuff.

You have a simple data structure. Learn how to use basic SQL with something easy. The code (connect to DB, SQL stuff) will all be same on a bigger DB. The difference will be that on a higher performance DB, you can't just "cat" the DB file to see what is going on.

You have a "wimp" DB. I mean 15K records with 5 fields that can be represented as a "flat" file, and that is only updated 3 times per minute, is "nothing". It will be fast enough. Get the code working then think about something more sophisticated.

Update:
Here is some very simple code to get you started:
the DBI::CSV didn't used to work on Windows, but it does now (Perl 5.10).
You will need to read a bit about SQL, but that knowledge will be transportable to other databases. Note that field names come from the file, like "username". This is exactly like an Excel spreadsheet can dump out.

#!/usr/bin/perl -w use strict; use DBI; #need to have DBI::CSV installed for this script my $db = DBI->connect("DBI:CSV:f_dir=./DEMO.db") or die "Cannot connect: $DBI::errstr"; my $get_rows = $db->prepare("SELECT * from DEMO.db"); $get_rows->execute() || die "can't fetch all rows"; while (my ($name,$username, $time, $n1, $n2) = $get_rows->fetchrow_array) { print "$time $name $username $n1 $n2\n"; } my $get_names = $db->prepare("SELECT username from DEMO.db"); $get_names->execute() || die "can't fetch all usernames"; while (my $name = $get_names->fetchrow_array) { print "$name\n"; } __END__ DATA IN THE FILE: DEMO.db: ------------------------------(this line not in this file) name,username,time,num1,num2 "John Smith",jhon99,"10:30:01",345,765 "John Smith",jhon98,"10:30:01",345,765 "Bob Smith",bsm01,"11:30:01",002,246 ABOVE CODE PRINTS: ------------ 10:30:01 John Smith jhon99 345 765 10:30:01 John Smith jhon98 345 765 11:30:01 Bob Smith bsm01 002 246 jhon99 jhon98 bsm01

In reply to Re: Query Language with Flat Files by Marshall
in thread Query Language with Flat Files by virtualweb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-24 09:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found