home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!bnr.co.uk!uknet!mcsun!sunic!seunet!enea!sommar
- From: sommar@enea.se (Erland Sommarskog)
- Newsgroups: comp.lang.perl
- Subject: wantarray bug in (syb)perl?
- Message-ID: <1993Jan5.130532.4698@enea.se>
- Date: 5 Jan 93 13:05:32 GMT
- Organization: Enea Data AB
- Lines: 60
-
- I haven't tracked down the following very closely. It was simply
- too easy to get around. But anyway, the code below doesn't seem
- to work if I say "if (wantarray)" instead of "if ($wantarray)",
- but seems to work OK when I catch wantarray in the beginning
- of the routine as I do.
-
- I wouldn't say that has made me lose sleep, but I though someone
- might be interest. If not, well another waste of bandwidth...
-
- sybperl -v
- This is perl, version 4.0
-
- $RCSfile: perl.c,v $$Revision: 4.0.1.4 $$Date: 91/06/10 01:23:07 $
- Patch level: 10
-
- Copyright (c) 1989, 1990, 1991, Larry Wall
-
- Perl may be copied only under the terms of either the Artistic License or the
- GNU General Public License, which may be found in the Perl 4.0 source kit.
-
- sub sql {
- local(@sql) = @_;
- ;# Calls dbcmd for each element in @sql with the default DB handle and
- ;# the default sepatator. Each row is returned as a string with lines
- ;# separated by $SQL_sep. Return value is scalar or array depending on
- ;# wantarray. If a scalar is required, and there is more than one row,
- ;# only the first is returned.
-
- local($line, @res, @data, $stat, $_, $wantarray);
-
- $wantarray = wantarray; # Seems to get cleared otherwise.
-
- foreach $line (@sql) {
- &dbcmd($def_handle, " $line") || &abort("dbcmd failed");
- }
-
- &dbsqlexec($def_handle) || &abort("dbsqlexec failed");
-
- while(($stat = &dbresults($def_handle)) != $NO_MORE_RESULTS) {
- &abort("dbresults failed") if $stat == $FAIL;
- while (@data = &dbnextrow($def_handle)) {
- foreach (@data) { s/^NULL$//; }
- push(@res, join($SQL_sep, @data));
- }
- }
-
- if ($wantarray) { # only "wantarray" always gives false here.
- @res;
- }
- else {
- if (length(@res) > 1) {
- $" = "\n";
- &abort("single-row query returned more than one row:\n@row");
- }
- $res[$[];
- }
- }
- --
- Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se
- Jag gav en k{ck tjeck en check.
-