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

Hi Monks;
From this code or better piece of code after the DB query has been done, e.g.:
... while (my $pointer = $sth->fetchrow_hashref){ $myfile_number = &cleaner ($pointer->{'file#'}); print $myfile_number; }

My question is the variable $myfile_number inside the while loop will bring back lets say about 10 file numbers results, what I am trying to do is to be able to store this results somehow and print the results outside of the while loop, how can I do that? Like:
... while (my $pointer = $sth->fetchrow_hashref){ $c++; $myfile_number = &cleaner ($pointer->{'file#'}); #print $myfile_number; Don't print here } print $myfile_number;

Been able to print the same result some how but been out side of the while loop.

Thanks for the help!

Replies are listed 'Best First'.
Re: While Loop
by gothic_mallard (Pilgrim) on Oct 21, 2004 at 14:01 UTC

    I think what you're wanting is to put the values you're getting into an array that can be seen thoughout the scope of the while and after it:

    my @myfile_numbers = (); while (my $pointer = $sth->fetchrow_hashref){ $c++; $myfile_number = &cleaner ($pointer->{'file#'}); push @myfile_numbers, $myfile_number; }

    Now you'd have the array @myfile_numbers available after the loop has completed containing the values you read in the order you read them.

    --- Jay

    All code is untested unless otherwise stated.

      Thank you, that will do it!!!! Thanks again!!!!!!