If you really want to use a BAD method, which you should NOT use:
while (...) {
     $total = $row[0];
     ...
}
print $total . "\n";

What you SHOULD do is:
use strict;
...
my $total = "";
while (...) {
     $total = $row[0];
     ...
}
print $total . "\n";


-David

On Tue, 17 Aug 2004 10:55:25 -0600, Wiggins d Anconia
<[EMAIL PROTECTED]> wrote:
> > After searching through the Perl Bookshelf CD, I have found that you can
> > declare a global and then use local() to change that value for a block
> > of code. I haven't found how to use a value from within a block of code
> > outside that block of code though. Is this possible? I'm sure I just
> > don't know what to search for in the bookshelf.
> >
> > EXAMPLE:
> > ========================================
> > while (my(@row) = $sth1->fetchrow_array)
> > {
> >     my ($total) = $row[0];
> >     print "Total Scanned:\t $total\n";
> > }
> >
> > print "Total:\t $total\n";
> >
> 
> Essentially you need to declare the variable at the proper scope level.
> So in this example, you need to declare $total outside of the loop,
> 
> my $total = 0;
> 
> For instance. For much more and a very good coverage of scoping, check out:
> 
> http://perl.plover.com/FAQs/Namespaces.html
> 
> http://danconia.org
> 
> 
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
>

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


Reply via email to