perl - Can anyone tell me where the bug is? -


             use strict;              use warnings;              open(file4,"cool.txt");              open(file6,">./mool.txt");              $line = <file4>;                while ($line ne "")              {                 @array = split(/,/,$line);                 $line = <file4> ;                 print file6 ($array[0]);                 print file6 ("\t");                 print file6 ($array[1]);                 print file6 ("\t");                 print file6 ($array[2]);              } 

these code have written in perl. code not working fine. giving tab space every nextline. dont need tab space every new line.let me show how output is.

          name         contact        email                        samy            32344245            hyte@some.com                        alex            231414124           coool@some.com    

this how see mool.txt file.the first line working fine.but nextline i'm facing tab space.i trying find out bug is.can please let me know code going wrong?i have gone through many times unable figure out.thank you

as asked im showing input file

        "name","contact","email"         "samy","32344245","hyte@some.com" 

put statement inside while loop. chomp should first line after reading line file. remove unwanted spaces.

use strict; use warnings; open(file4,"cool.txt"); open(file6,">./mool.txt");  while (<file4>) {      chomp; #this remove unwanted spaces      @array = split(/,/,$_); #$_ represent line read      print file6 ($array[0]);      print file6 ("\t");      print file6 ($array[1]);      print file6 ("\t");      print file6 ($array[2]);      print file6 ("\n");  } 

Comments

Popular posts from this blog

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -