mukrz has asked for the wisdom of the Perl Monks concerning the following question:

One field of data returned from a database is the string value "IO" (there are ~10 other two-character codes). I am able to print out all other codes with:
print "$db[0]\n";
However, using Perl (5.6.1 build 633 with DBI 1.37 to query Oracle) I am unable to show or use any records that have "IO".
I do not specify "use IO;" in the program, but is it possible that perl thinks that I am trying to use the IO modules?
sample database rows:
"abc123","AB" (this works just fine)
"def234","IO" (perl pretends that this record does not exist)
"ghi345","BC" (this works just fine)

What I'm trying to do:
$sql = "select * from mytable";<BR> while (@data = $sth->fetchrow()) {<BR> mkdir($data[1]) if (! -d $data[1]);<BR> }

The result is two directories (from sample data) named "AB" and "BC". There are no error messages.

Replies are listed 'Best First'.
Re: Strange Missing Data
by kvale (Monsignor) on May 15, 2004 at 18:43 UTC
    I do not see any obvious problems with the code. To help track this down,(1) try printing each row to stdout to see if the record is even returned, (2) see if the mkdir returns an error code.

    Also, you mention IO as being in $db[0] at the beginning of your post, but in $data[1] in the second snippet; check that you have the correct field number.

    One final thought: if your DB never shows any records with IO, how do you know it was ever properly entered into the database?

    -Mark

      Bad editing (@db = @data)

      Your last comment put me on the right track - the data was not entered in the correct column.

      Thanks!
Re: Strange Missing Data
by bart (Canon) on May 15, 2004 at 22:34 UTC
    I think all that is happening is that for some reason, you can't create a directory "IO". You don't check the return value of mkdir, you better would. Maybe like this, eliminating use of the database entirely:
    my $dir = 'IO'; mkdir $dir or die "Can't create directory: $!" unless -d $dir;
Re: Strange Missing Data
by graff (Chancellor) on May 16, 2004 at 02:05 UTC
    To expand slightly on the previous reply, your code would try but fail to make a directory named "IO" if there were already a data file named "IO" in the current working directory. (But the other doubts raised in the first reply deserve inspection as well.)