Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Getting info with a small flatfile db.

by snowcrash (Friar)
on Aug 03, 2001 at 09:49 UTC ( [id://101892]=note: print w/replies, xml ) Need Help??


in reply to Getting info with a small flatfile db.

hi!

as usually, there are quite a lot of ways to do it. although you could write the code for parsing a individual line yourself, using split or regular expressions, i would recommend to use a module like Text::CSV_XS that does the work for you.

some sample code could look like this:
use Text::CSV_XS; my $csv = Text::CSV_XS->new({ 'quote_char' => '"', 'escape_char' => '"', 'sep_char' => '|', 'binary' => 1 }); while my $line (<YOURFILE>) { if ($csv->parse($line)) { my @field = $csv->fields; my $count = 0; for $column (@field) { print ++$count, " => ", $column, "\n"; } print "\n"; } else { my $err = $csv->error_input; print "parse() failed on argument: ", $err, "\n"; } }

snowcrash //////

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found