How to remove perl reverse extra line -


could point out mistake?

while(<stdin>){   $reverse = reverse $_; #(explicit - force casting)   if( 5 <length ){         print "reverse $reverse\n";   }   else{     print; #this print $_ scalar context   } } 

execute program,

1234567 reverse 7654321 

but if change print "reverse $reverse\n"; print "$reverse\n"

1234567  7654321 

can explain going on? , how remove newline?

the reverse of "1234567\n" "\n7654321". if want strip out newline before reversing, can use the built-in chomp function:

while(<stdin>){   chomp;   $reverse = reverse $_; #(explicit - force casting)   if( 5 <length ){         print "reverse $reverse\n";   }   else{     print "$_\n"; #this print $_ scalar context   } } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -