Rightly said by Gunnar. To see all the values stored in @array add: foreach (@array) { print "$_\n"; }
On 9/2/07, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: > > Rodrigo Tavares wrote: > > Hello, > > > > I have a problem with a counter. > > > > #!/usr/bin/perl > > > > use strict; > > use warnings; > > > > print "Write a number:"; > > my $number= <STDIN>; > > > > my @array; > > my $div = $number * 2 ; > > my $i=0; > > > > while ($div > 0) > > { > > $div = $div / 2; > > $array[$i]=$div; > > $i++; > > } > > > > print "Value i is: $i\n"; > > > > print "$array[0]\n"; > > print "$array[1]\n"; > > print "$array[2]\n"; > > print "$array[3]\n"; > > print "$array[4]\n"; > > > > When I run the script: > > > > Write a number:23 > > Value i is : 1081 > > 23 > > 11.5 > > 5.75 > > 2.875 > > 1.4375 > > > > Why did script show the value ? > > > > The counter must be six. > > Try > > while ($div > 1) > > and you'll notice a difference. > > -- > Gunnar Hjalmarsson > Email: http://www.gunnar.cc/cgi-bin/contact.pl > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > >