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:
Store data fields efficeintly

 



yapp
User

Nov 24, 2001, 8:25 AM

Post #1 of 4 (997 views)
Store data fields efficeintly Can't Post

Hello there.

I want to store these data fields efficiently in a flat-text file, it's about a download manager file:
- general download information (name, size, date)
- Locations of the download (title/url)
- Features of the download
- Requirements
- Log of downloads.

How can I store that efficiently. I don't want to store each type in a different file. How can I do that?


Yet an Other Perl Programmer

_________________________________
Find out more about programming
http://www.cool-programming.f2s.com


wickedxter
User

Nov 24, 2001, 2:19 PM

Post #2 of 4 (994 views)
Re: Store data fields efficeintly [In reply to] Can't Post

well you could put it all on one line and split the data.
i.e.
Name|size|data~~title|url~~features~~Req.~log

then just rig a sub to pull out all the info and return it to do what ever with...



Ovid
newbie

Nov 24, 2001, 2:25 PM

Post #3 of 4 (994 views)
Re: Store data fields efficeintly [In reply to] Can't Post

Storing this data "efficiently" is very subjective. Do you mean fast access times, easy to parse or smallest amount of disk space?

In any event, I would guess that you mean "easy to parse". I would check out Text::CSV_XS. Here's a basic sample to show you how to create a CSV string:


Code
use strict; 
use Text::CSV_XS;


my $csv = Text::CSV_XS->new;
my @data = ( "Ovid", 3, '"This field has quotes"' );

my $status = $csv->combine(@data); # combine columns


if ( ! $status ) {
&some_error_routine;
} else {
print $csv->string;
}

To read the data:


Code
$status = $csv->parse($record); 
@data = $csv->fields;

See "perldoc Text::CSV_XS for more details.

You could also use DBD::CSV. This is useful if you find that you need to switch to a database as this will limit the amount of code changes you will need to make.



yapp
User

Nov 25, 2001, 4:30 AM

Post #4 of 4 (991 views)
Re: Store data fields efficeintly [In reply to] Can't Post

Well, with efficient I mean that:

- There shouldn't be tons of files to store all the different items (like 400 files for 25 downloads)
- Storing all the data in one file can also be difficult, since that requires much more programming work.

Most of the tables (you can call them that) have a variable size. It's easy off course to store each table in a different file, and loading that into an array with @lines = <FH> However, it's better to place some more bytes in the same file, I can use some split functionality...

But speed in the file IO would be welcome...
That's why I am so keen one binary files, wherein you can just jump to the right character. However, I find it very difficult in perl to make that compatible for transfering.


I need a mix between putting all data into one file, and store each table in a different file. I don't know what mix is better.

Yet an Other Perl Programmer

_________________________________
Find out more about programming
http://www.cool-programming.f2s.com

 
 


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

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