[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-beginners
Subject:    Re: Debug
From:       pawan kumar <pawan.be.kumar () gmail ! com>
Date:       2010-09-27 11:24:09
Message-ID: AANLkTimnYc9Ge5UuYk_t2bTH0iAo0nav6q-6YBxZ4POt () mail ! gmail ! com
[Download RAW message or body]


Hi John,
           This is pawan.Thank for the all the inputs regarding program.John
its working.
Great john.
Thank you.


On Mon, Sep 27, 2010 at 3:32 PM, John W. Krahn <jwkrahn@shaw.ca> wrote:

> 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;
>> $len=@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-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>


-- 
K.V. PAWAN KUMAR


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic