[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Flat files and variable miles



>my $Var1,$Var2,$Var3..$Var50 = @_
>
> Will this work? Or is it impractible?

Yes, it should work but I like the ability to refer to my fields by name.

-----START CODE------

$fieldNames = "lastName,firstName,phone,address,etc.";
@fields = split(",",$fieldNames);
$fieldDelimiter = "\t"; # or whatever you use

while (<DATA>) {
	@recordFlds = split($fieldDelimiter,$_);
	for($flds=0;$flds<@fields;flds++);
		$field{$fields[$flds]} = $recordFlds[$flds];
	}
	print $field{"lastName"};
	print $field{"firstName"};
	print $field{"phone"};
	print $field{"address"};
	 # etc.
}

-------END CODE------

Warning. This code is off the top of my head. I use this technique often
but haven't tested this particular code.

The field names list may be hardcoded in your program, in a separate file
that you'll have to read, or in the first record of your file.


David Seay
http://www.mastercall.com/g-s



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org