in reply to Re: Using 2d hash to print a matrix
in thread Using 2d hash to print a matrix

How do you print the tab de-limited values in this code? I did the following but it puts a tab in first column as well instead of just tab limiting after first columns. I am learning about this join command so i apologize for dumb questions.

print OUTD2 join("\t", q{ }, $k, @data), qq{\n};

Replies are listed 'Best First'.
Re^3: Using 2d hash to print a matrix
by atcroft (Abbot) on Oct 28, 2011 at 21:40 UTC

    You don't need the 'q{ }' in the line then. The join() command assembles a single string from the second and following parameters using the first parameter as a separator. So, if you said $str = join(q{asdf}, 1, ( 2, 4, 6 ));, then $str would contain '1asdf2asdf4asdf6', or if you said $str = join(q{|}, qw/a s d f z x c v/);, $str would contain 'a|s|d|f|z|x|c|v'. In the line you mention, there would be a space, followed by a tab character, then the value of $k, then a tab character, then the values in @data, separated by tab characters.

    Hope that helps.