Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
more useful options
 
PerlMonks  

Re: Assigning scalar to each field in a flat file database

by BeernuT (Pilgrim)
on Mar 07, 2002 at 22:26 UTC ( [id://150216]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Assigning scalar to each field in a flat file database

look at reading perlfunc:open and perlfunc:split, something like this is what your looking for
my @array = split(/\|/, $_);
or if you know the variables you have use something like:
my($var1, $var2, $var3) = split(/\|/, $_);
let me know if you need any help.

-bn

Replies are listed 'Best First'.
Re: Re: Assigning scalar to each field in a flat file database
by Anonymous Monk on Mar 08, 2002 at 22:30 UTC
    Hi, thanks for the post, still having heartache! my text file looks like this:
    data|data1|data2|<BR> data3|data4|data5|data6<BR><BR> and so forth...there are about 87 fields split in no particular order +over 28 lines. So, what am I doing wrong? I am getting an internal +server error when I use the following code:<BR><BR> #!/usr/bin/perl -w<BR> print "Content-type:text/html\n\n";<BR> open (DATA, "<../../cgi-bin/tracking_1_db.txt") || die;<BR> while (<DATA>) {<BR> my @items = split (/|/, $_);<BR> }<BR> close (DATA);<BR> <HTML><BR> <HEAD><BR> <TITLE>Perl Test Script 1</TITLE><BR> </HEAD><BR> <BODY><BR> $items[0];<BR> $items[1];<BR> </BODY><BR> </HTML><BR>
      Well you kinda missed/ignored the code i posted. The split function takes a regular expression /PATTERN/ and in a // the character '|' is an 'or'. So use /\|/ instead.
      @array = split(/\|/, $_);
      That should help you out a little more.

      -bn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://150216]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.