> From: james varghese [mailto:james2...@gmail.com] > Sent: Tuesday, October 11, 2011 8:31 AM > To: beginners@perl.org > Subject: perl script help > > hi, > I am new to perl programming.I am trying with the following script and > need help for it. > > I consolidated 10 excel files(in .txt format) which has same headers > in it and so i made it 1 common header at the top.While doing it,in > final output file i see a blank row at the beginning of every file > consolidated.I wanted to get rid of it and to be displayed all in a > single file. > > Sample Script: > > while(<FILE>) { > if (($k ==0) and ($Line_Counter ==1)) { > my @F=split(/[\t]+/, $_); > print CONSOL_FILE "$F[0] \t $F[1] \t $F[2] \n"; > } > if (($k >=1) and ($Line_Counter>1)) { # doesnt > print headers > $Line=$_; > my @F=split(/[\t]+/, $Line); > print CONSOL_FILE "$F[0] \t $F[1] \t $F[2] > \n"; > } > $Line_Counter = $Line_Counter + 1; > } > close FILE ; > note:tab is the delimiter used here. > > Any help is Appreciated. >
Hi, Not certain if this is your problem, but you probably want to 'chomp' the input after reading a line. Also, what is $k? You may be able to read the first line outside the loop and print the header. Then you would not have to worry about the checks for $line_number (and $k?). And why do you assign $Line to $_? Seems like an unnecessary step. As an aside, when referring to the Perl programming language it is usually capitalized (Perl). Ken -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/