On Jan 2, 2008 6:21 AM, Siva Prasad <[EMAIL PROTECTED]> wrote:

> I have a problem printing values of DBI statement handle into a text file.

I have a problem reading your message, since it's all blue. Please,
don't do that.

> If I print the values in statement handle  on the STDOUT I am able to see
> the values in it.

> But If I print the same in a text file no values are written in the handle.

Then the problem is in the way you're doing the printing. There's no
need to drag DBI into this.

> Please check the piece of code below:

Sure, don't mind doing it at all. That's what I'm here for, after all.
By the way, do you ever step through your code in the perl debugger to
see what it's doing along the way? I suspect that it could be an
enlightening experience.

> foreach my $CLASS_ID (keys %CLASS_ID_HASH)
>
> {
>
>
>
>   foreach my $STR (@SEARCH_STRS_ARRAY)
>
>    {
>
>              foreach my $COL (@CLASS_SEARCH_COLS)
>
>              {
>
>                        my $FILE = $COL . "_" . $STR . ".txt";
>
>                         $FILE =~ s/\s+//g;
>
>                         $FILE = "$BASE_RESULTS_FOLDER" . "//" . "$DIR_NAME"
> . "//" . $FILE;

Why do you name your variables in all caps? Perl is generally more
readable when most variables are all lower case.

Your code could be simplified if you used double-quote interpolation
instead of low-level string operators like '.'.

You may benefit from studying Perl code that has been written by someone else.

>                         (open my $TEMP_FILE_HANDLE, '>', "$FILE") or die
> "$!";

Since you're deep in three nested loops at this point, this is a lot
of potential "TEMP" filehandles. That's a red flag.

This statement wipes out any existing file named $FILE. Since you're
not finding the data you want, that's another red flag. Could a later
iteration use the same $FILE as an earlier one? It seems quite
probable.

>                         my $SQL="select class_id,title,description,tags from
> $TABLE where $COL LIKE \'$STR\' AND class_id=\'$CLASS_ID\'";

You should learn sooner rather than later about SQL injection. But
that's neither this problem nor this forum.

    http://xkcd.com/327/

>                         my $results=$DB_CLASS_OBJ->RETRIVE_DATA($SQL);
>
>                         (open my $FH, '>>', "$FILE") or die "$!";

How many filehandles are open to the same file, anyway? Is that a red
flag or a red herring?

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to