0

I have an issue that is driving me mad because I really think it's absurd.. What horribly obvious thing am I missing here?

this is a little snippet of code:

use XBase;
use strict;

my $table = new XBase $filename or die XBase->errstr;
my $cursor = $table->prepare_select("ID", "NAME", "STREET");
while (my @data = $cursor->fetch) {
   ### do something here, like print "@data\n";
}

obviously this simple code has a specific function: a connection is made and data is retrieved.. Everything runs fine..

..but if I try to pass the fields list as the content of a string, as in the snippet below, something goes wrong and no data is retrieved:

use XBase;
use strict;

my $test = '"ID", "NAME", "STREET"';
my $table = new XBase $filename or die XBase->errstr;
my $cursor = $table->prepare_select($test);
while (my @data = $cursor->fetch) {
   ### do something here, like print "@data\n";
}

it seems that prepare_select() does not like at all a list of fields contained inside a string.. ..but probably I'm missing the usual horribly obvious thing..! ;)

Cris

1 Answers1

0
->prepare_select('"ID", "NAME", "STREET"')

is not the same as

->prepare_select("ID", "NAME", "STREET")

The first passes one string consisting of 22 characters while the second passes three strnig of 2, 4 and 6 characters respectively.

To obtains the three string ID, NAME, STREET from the string "ID", "NAME", "STREET", you can use the following:

my $fields = '"ID", "NAME", "STREET"';
my @fields = $fields =~ /"([^"]*)"/g;
ikegami
  • 367,544
  • 15
  • 269
  • 518