pawan kumar wrote:
Hi guys  i need your folks help:
Problem:I have to accept the elements into array and multiply  each element
of array by 2 and print the resulting array.
If input of array is (2,3)
i Expect output as (4,6)
but output is (0,4,6).
why is tht zero cuming.


#!/usr/bin/perl

You should probably use the warnings and strict pragmas to let Perl help you find mistakes.

use warnings;
use strict;


print "Content-type: text/html\n\n";
print "<html><h1>Hello!</h1></html>\n";
@arr=undef;

You are assigning undef to the first element of the array @arr and undef in numerical context is 0.


print "dude how many numbers";
$num=<STDIN>   ;

You should use chomp() to remove the newline.


$i=0;
while($i<$num)
{
print " number enter madho \n";
$inp=<STDIN>;
push(@arr,$inp);
$i++;
}
print @arr;
$l...@arr;
print "len=$len\n";

foreach $num (@arr){
  $num *=2;

Here undef * 2 is the same as 0 * 2 so the first element becomes 0.


  print "$num\n";
  #$arr{$i}=($i*5);

  }

   print "finally : @arr";



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to