I'm astonished I haven't encountered this until now (or at least,
noticed it until now): by default, split() silently doesn't return
trailing empty strings!
I've since learned about setting the LIMIT parameter to -1.
Thinking now that I should revisit every split() I've ever written.
There always turns out to be a Very Good Reason for any Perl behavior
that first strikes me as odd (it's usually that I've done something in
a bone-headed way). In this example, snipped for brevity, I'm
accessing rows of a RDBMS, where the rightmost cell happened to be
null. It doesn't seem all that extraordinary a task. In light of
this, I'd be interested in being enlightened by some Old Hands why
this is split()'s default behavior (and, very likely, what I'm doing
that's boneheaded ;-)
Thanks,
Chap
my @dbf_cols = qw{SCHOOLNUM
ALTNUMBER
SCHOOLABRV
NAME
DISTNUM
};
my $sql
= "select "
. join( ',', @dbf_cols ) . " "
. "from ASCH "
. "where SCHOOLNUM = '$schno'";
#
# can't find good free way to access directly with DBD::, but this
works..
# it writes the result as tab-separated-values, with line-endings.
#
my @rows = qx(java lmi_DBFAccess -q "$sql");
chomp @rows;
# have verified that, at this point, trailing empty fields still remain.
my @vals = split( "\t", $rows[0] ); # Bang! gone
my $sqlite
= "INSERT INTO schools ("
. join( ", ", @dbf_cols )
. ") VALUES ("
. join( ", ", map( "'$_'", @vals ) ) . ")";
At this point I have a SQL INSERT statement that lists 5 columns and 4
values.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/