Hi Monks,

I have what seems to me to be a straightforward task: to output the contents of an array of hashes into a DBF file via XBase.

I've been poring over the XBase Docs and FAQ and I can't seem to figure this out. The problem is that the object I should be creating with XBase, isn't recognized by XBase. Here's the code:

use XBase; ... my $new_table = XBase->create("name" => "$filename.$ext", "field_names" => @column_names, "field_types" => undef, "field_lengths" => undef, "field_decimals" => undef); my $i=0; foreach my $record (@records) { $new_table->set_record_hash($i,%$record); $i++; } $new_table->close;

The problem is, I get an error message: "Can't call method "set_record_hash" on an undefined value at /home/www/xina-cgi/libexec/xiexport.cgi line 264." Which I take to mean that it doesn't recognize $new_table as an XBase object.

So I thought that perhaps once I created the new table, I needed to define a new XBase object, and I tried this:

my $new_table = XBase->create("name" => "$filename.$ext", "field_names" => @column_names, "field_types" => undef, "field_lengths" => undef, "field_decimals" => undef); my $dbf = new XBase "$filename.$ext" or Xina::util::graceful_e +xit("xiexport","Problems with DBF file.","$filename.$ext:".XBase->err +str." from $remote_host"); my $i=0; foreach my $record (@records) { $dbf->set_record_hash($i,%$record); $i++; } $dbf->close;

Except now, I get the error: "Error opening file xxx.dbf: No such file or directory" - it doesn't create the file in the first place (I verified that by looking at the directory). But there is no error thrown on the create step. So I'm stumped. The directory is writeable, blah, blah, there are no file permission issues here.

Thanks for any pointers!

Michelle

In reply to XBase File output by michellem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.