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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |