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 09, 2002 at 03: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