[comp.lang.perl] dbaseiii structure

frech@mwraaa.army.mil (Norman R. Frech CPLS) (06/02/90)

I am attempting to read the structure of an empty dbaseiii file and
extract just the field names.  I am using the following perl script
which almost works.  Some of the fields end up with an extra character
at the end and those which begin with a "F" are split and the "F" is
dropped.  It also gives extraneous characters at the beginning and drops
characters at the end. If anyone has any suggestions I am all ears.

$/ = "F\245F";
$\ = "\n";
while (<>)
{
chop;
s/\W//g;
$len = length;
$_ = substr($_,0,$len - 1);
print;
}
 
Norm Frech ( frech@mwraaa.army.mil )

merlyn@iwarp.intel.com (Randal Schwartz) (06/29/90)

In article <1990Jun1.182515.16801@uvaarpa.Virginia.EDU>, frech@mwraaa (Norman R. Frech CPLS) writes:
| I am attempting to read the structure of an empty dbaseiii file and
| extract just the field names.  I am using the following perl script
| which almost works.  Some of the fields end up with an extra character
| at the end and those which begin with a "F" are split and the "F" is
| dropped.  It also gives extraneous characters at the beginning and drops
| characters at the end. If anyone has any suggestions I am all ears.
| 
| $/ = "F\245F";

$/ is only one character long.  Quoting from the relevant portions of
the manual:

     $/      The input  record  separator,  newline  by  default.
             Works  like  awk's  RS  variable, including treating
             blank lines as delimiters if set to the null string.
             If  set  to  a value longer than one character, only
             ====================================================
             the first character is used.  (Mnemonic: /  is  used
             ============================
             to delimit line boundaries when quoting poetry.)

So, you are splitting on all "F" characters.  Probably not what you
want.  Maybe:

	undef $/;
	@lines = split(/F\245F/,<>);

will do what you want.

Just another Perl hacker splitting hairs,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

frech@mwraaa.army.mil (Norman R. Frech CPLS) (06/30/90)

Concerning the reading the structure of dbaseiii files, Glen Gordon
sent me perl script which does the same format as a 'disp struc' out
of dbase.  It has saved me a lot of work.  BTW, thanks a heap Glen!!!
I had problems reaching your machine with the thank you.  I am not
sure if Glen wants his code posted, he is at ggordon@agsm.ucla.edu.

Norm Frech < frech@mwraaa.army.mil >