Re: different field delimiters - newbie ques.

From: Jeff Zucker (jeff_at_vpservices.com)
Date: 05/14/04


Date: Thu, 13 May 2004 17:23:00 -0700
To: leegold <leegold@fastmail.fm>

leegold wrote:
> ...snip...
>
>> DBD::AnyData allows you to create your own formats though. If
>>you don't have embedded '###' in your data, then this simple three line
>>module will allow DBD::AnyData to parse files with '###' as a field
>>separator. Just Save this file under the name 'ThreeSharp.pm' in the
>>AnyData/Format directory where your copy of AnyData is located:
>
>
> Say I implement "threesharp" per the post. If I make the first record
> before the actual data
>
> name###address###hobby
>
> Will it automagically know when I refer to these fields
> w/sql?

Yes.

>
> Also is it standard to have
>
> ###name###address###hobby### vs. the above?

No. And that's why it should be called a threeSharp *separated* file,
not a threeSharp *delimited* file. Delimiters go around things,
separators go between them. CSV is comma SEPARATED values, meaning
there are commas BETWEEN the values. And your format should probably
behave the same way unless you have a legacy format to maintain. If you
have data that comes in with the extra ### at the start and end and you
need to keep it that way, you can just modify your read sub to strip
them off and your write sub to stick them on.

> If it's rtfm please link me appreciate the help.

Well, it never hurts to R the fine M, but since I can't point you to a
specific place that addresses your questions, I'm answering here. You
can look through the various AnyData/Format/*.pm modules and see from
their documentation and their code how they behave, but I don't think
you'll need to just to parse the format you're interested in, it should
just work. Try it and let us know how it turns out.

-- 
Jeff
>>     package AnyData::Format::ThreeSharp;
>>     use base 'AnyData::Format::Base';
>>     sub write_fields  { shift; sprintf "%s\n",join '###',@_ }
>>     sub read_fields   { split '###', $_[1] }
>>     1;
>>
>>Then in your perl script do this:
>>
>>     use DBI;
>>     my $dbh = DBI->connect('dbi:AnyData(RaiseError=1):');
>>     $dbh->ad_catalog( $table_name, 'ThreeSharp', $file_name);
>>     #
>>     # you can now use any SQL you want to access/modify $table_name
>>     # results will be stored in $file_name with '###' as a field
>>     # separator
>>
>>-- 
>>Jeff
>>
>>
> 
> 


Relevant Pages