Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Getting info with a small flatfile db.

by thatguy (Parson)
on Aug 03, 2001 at 09:45 UTC ( [id://101891]=note: print w/replies, xml ) Need Help??


in reply to Getting info with a small flatfile db.

you don't need the line number to access the info in your db, but this should work for you.

use strict; use vars qw/ $lines $blah1 $blah2 $blah3 /; sub count_lines { $lines = 0; open(FILE, "filename"); while(<FILE>) { $lines += ($_ =~ tr/\n//); } print "$lines lines in filename\n"; close (FILE); } sub breakup_lines { open(FILE, "filename"); while(<FILE>) { ($blah1,$blah2,$blah3) = split(/\|/, $_); ## do something with the blahs } close (FILE); }

also you may want to check out these nodes: Another flatfile thingy & Poor Person's Database and how could we forget the Super Search?

Update: I see you don't know how many columns you are going to have. so instead use

sub breakup_lines { open(FILE, "filename"); while(<FILE>) { push @blah, (split /\|/); ## do something with the @blah } close (FILE); }
.

then you can do whatever with @blah (oh and add @blah to the vars statement at the top.)

-p

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-28 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found