>>>>> "JLR" == James Linden Rose, <[EMAIL PROTECTED]> writes:
JLR> I have a data file whose field order is fluid, but whose names are
JLR> known, and whose records are delimited by returns, and whose fields
JLR> are delimited by tabs. The data file is stored in say @File. But
JLR> the first record contains the one word name of the field. So I build
JLR> an array - let's call it @rray = split (/\t/, $File[0]); , that
JLR> contains all of the field names in the current order of the file.
this is a standard flat file DB.
call that array @fields
JLR> Then when I want to build some output based on record $x of this
JLR> file, I create say:
JLR> @Record = split (/\t/, $File[$x]);
that looks like you have read in the whole file and are indexing by line
number which is usually not efficient.
in any case this is better:
@record{ @fields } = split (/\t/, $File[$x]);
this creates a hash with that record's fields in it, access by field
name.
JLR> Now I want to organize my logic by being able to call up say
JLR> $Record[$address], or $Record[$phone_num], etc etc.
now you access them by 'address', 'phone_num' etc.
JLR> To do that I need $address to contain the position of the "address"
JLR> field, gleaned from the current order of the fields contained in
JLR> @rray. So if @rray currently looks like qw (address phone_num fax
JLR> note), I need:
JLR> $address = 0;
JLR> $phone_num = 1;
JLR> $fax = 2;
JLR> $note = 3;
no you don't need that.
JLR> print "Record $x's Phone Number is: $Record[$phone_num]\n";
print "Record $x's Phone Number is: $Record{'phone_num'}\n";
JLR> But I'm not sure what no strict would do, nor what yardage an
JLR> eval does me.
strict stops you from doing dangerous things like you are trying to do.
but you aren't event using strict. the other post was trying to remove
strictures to enable symrefs to work. you should use strict and hashes
as i have shown above.
read perlref, perllol and perldsc to learn more on how to use perl data
structures. your needs are very simple and common and you are going in
the wrong direction to solve them.
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org