On Wed, 2 Jan 2013 16:05:25 +0530 Neeraj <neeraj.seh...@gmail.com> wrote:
> Why do i have white-space between words when printing array while not > getting white-space when printing individual element. perlfaq explains this - from perlfaq5: Why do I get weird spaces when I print an array of lines? (contributed by brian d foy) If you are seeing spaces between the elements of your array when you print the array, you are probably interpolating the array in double quotes: my @animals = qw(camel llama alpaca vicuna); print "animals are: @animals\n"; It's the double quotes, not the "print", doing this. Whenever you interpolate an array in a double quote context, Perl joins the elements with spaces (or whatever is in $", which is a space by default): animals are: camel llama alpaca vicuna This is different than printing the array without the interpolation: my @animals = qw(camel llama alpaca vicuna); print "animals are: ", @animals, "\n"; Now the output doesn't have the spaces between the elements because the elements of @animals simply become part of the list to "print": animals are: camelllamaalpacavicuna You might notice this when each of the elements of @array end with a newline. You expect to print one element per line, but notice that every line after the first is indented: this is a line this is another line this is the third line That extra space comes from the interpolation of the array. If you don't want to put anything between your array elements, don't use the array in double quotes. You can send it to print without them: print @lines; -- David Precious ("bigpresh") <dav...@preshweb.co.uk> http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook www.preshweb.co.uk/cpan www.preshweb.co.uk/github -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/