http://qs1969.pair.com?node_id=1227731


in reply to Doubt in code - Beginner in perl

I couldn't reproduce your error. I've run your code, and the output is exactly what you expected.

Are you sure you posted the code that generated the error?

The error seems to be that the newline is chomp'ed only from the first element of @words (which is "Perl\n"). Note that your output contains the string "Perl" twice - once with a newline (which appears two time in the input list) and once without a newline (which appears once. That is, the newline was chomp'ed only once). All the rest of the elements of @words appear in the output with a newline.

However, your code chomp(@words=<STDIN>) really does the work. It really chomp's the newline from all the elements. At least for me...