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
Post a Comment