Ok.. Im pulling my hair out and it hurts.. Im going to stop.. I don't what to get premature baldness. Can someone enlighten me on some code..

Im writing some code that involves a couple List of a List. I noticed that when I was printing out one of the lists, I was getting spaces between the elements within the list items. So to figure out why, I wrote the following code to find what was causing the spaces. I made subroutines to simulate the different kind of ways I was using list data. It appears the spaces where caused by the interpolation of the variable in one of my print statements but I dont understand why. All the cases do what I was expecting except the last print of data from SUB4.

Why is SUB4: 2nd way being printed differently then SUB4??

#!/usr/bin/perl -w use strict; sub my_sub () { return ("1", "2", "3"); } sub my_sub2 () { my @data = (); for my $x (1..3){ push @data, ["1","2","3"]; } return @data; } sub my_sub3 () { my $test_str = "1::2::3\n"; (my @data) = $test_str =~ /^(\d{1})::(\d{1})::(\d{1})/; return @data; } sub my_sub4 () { my @data = (); while (<main::DATA>){ chomp; push @data, [split /::/]; } return @data; } print "SUB1:\n"; print my_sub(),"\n\n"; print "SUB2:\n"; for my $x (my_sub2()){ print @$x,"\n"; } print "\n"; print "SUB3: \n"; print my_sub3,"\n\n"; my @data = my_sub4(); print "SUB4: \n"; for my $x (@data){ print @$x,"\n"; } print "\n"; print "SUB4: 2nd way\n"; for my $x (@data){ print "@$x\n\n"; } __END__ 1::2::3 1::2::3 1::2::3

Here is the output:

SUB1: 123 SUB2: 123 123 123 SUB3: 123 SUB4: 123 123 123 SUB4: 2nd way 1 2 3 1 2 3 1 2 3

Thanks for any help!
zzSPECTREz


In reply to Help with @LoL by zzspectrez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.