FAQ 5.38 Why do I get weird spaces when I print an array of lines?
am 23.12.2007 15:03:03 von PerlFAQ ServerThis is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
------------------------------------------------------------ --------
5.38: Why do I get weird spaces when I print an array of lines?
Saying
print "@lines\n";
joins together the elements of @lines with a space between them. If
@lines were "("little", "fluffy", "clouds")" then the above statement
would print
little fluffy clouds
but if each element of @lines was a line of text, ending a newline
character "("little\n", "fluffy\n", "clouds\n")" then it would print:
little
fluffy
clouds
If your array contains lines, just print them:
print @lines;
------------------------------------------------------------ --------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.