in reply to Database question: pulling a particular field from a flat database

The database that I am working with looks something like this:
ID|Category|Name|Image|Description|Price|Taxable|thumb|Listing
The first part of the script, shown below, looks through the db for the first field, or in this case, "ID" field. I want the first part of this script to use the "Listing" field instead of the "ID" field.
open DATA,$data; $line=<DATA>; @fields=split('\|',substr($line,0,index($line,";"))); %data=(); while (<DATA>) { my(@flds)=@fields; shift(@flds); my(@temp)=split('\|',substr($_,0,index($_,";"))); my($id)=shift(@temp); while ($#flds>-1) { if ($temp[0] eq "no") { $temp[0]=""; } $data{$id}{shift(@flds)}=shift(@temp); } } close DATA;

Replies are listed 'Best First'.
Re: Elaboration on my Database question
by Sifmole (Chaplain) on Sep 05, 2001 at 18:44 UTC
    You are splitting the data into an array. You have already told us that you know the field you want is the eighth. You can access any element of the array you want via $foo[n] where n is the index of the field you want. Since arrays start counting at 0 ( normally at least, it can be changed but I am going to assume you haven't ), the eigth element can be gotten at index 7 --
     my $id = $temp[7].

    Is that enough?