Thanks Tim

Regards.../om

On 14-Mar-2012, at 17:36, timothy adigun <2teezp...@gmail.com> wrote:

> Hi,
> 
> On Wed, Mar 14, 2012 at 12:37 PM, Torqued <torque.in...@gmail.com> wrote:
> It worked like charm, but a quick question, why the print is misbehaving 
> under the loop, but once out how it print right result.
>     Under the loop, using your push function, it increases the value in array 
> @column, and with the join function it prints what is in the array as it 
> adds! Please don't forget the while loop works till there is no more "line" 
> to read in from __DATA__ by $_.
> 
This means if there are more rows in __DATA__ it will keep on bunching them so 
many times.  

Thanks for explaining.
> Regards.../om
> 
> On 14-Mar-2012, at 16:54, timothy adigun <2teezp...@gmail.com> wrote:
> 
>> OR use:
>>   #!/usr/bin/perl -w
>>   use strict;
>> 
>>  my @column;
>> while (<DATA>) {
>>        push @column, (split)[0];  
>> }
>>  print join " ",@column;
>> 
>> __DATA__
>> 1 a b c
>> 2 d e f
>> 3 g h i
>> 
>> On Wed, Mar 14, 2012 at 12:19 PM, timothy adigun <2teezp...@gmail.com> wrote:
>> Hi Torqued,
>> 
>> On Wed, Mar 14, 2012 at 11:51 AM, Torqued <torque.in...@gmail.com> wrote:
>> I have a code which goes like this
>> 
>> #!/usr/bin/perl -w
>> use strict;
>> 
>> my @column;
>>     my $k; 
>> while (<DATA>) {
>>        push @column, (split)[0];
>>        #print join (' ', @column);
>>           $k=join (' ', @column);
>> }
>>      print $k; 
>> ***OUTPUT**
>>      1 2 3
>>  
>> __DATA__
>> 1 a b c
>> 2 d e f
>> 3 g h i
>> 
>> But when running this i get the output as : 11 21 2 3
>> Whereas i am trying to get the output as : 1 2 3
>> 
>> could you please suggest what i am doing wrong here?
>> 
>> Regards.../om
>> 
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>> 
>> 
>> 
>> 
>> 
>> -- 
>> Tim
>> 
>> 
>> 
>> 
>> -- 
>> Tim
>> 
> 
> 
> 
> -- 
> Tim
> 

Reply via email to