Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

printing out tabs between each element in an array

by Win (Novice)
on Feb 18, 2008 at 13:07 UTC ( #668523=perlquestion: print w/replies, xml ) Need Help??

Win has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: printing out tabs between each element in an array
by marto (Cardinal) on Feb 18, 2008 at 13:33 UTC
Re: printing out tabs between each element in an array
by haoess (Curate) on Feb 18, 2008 at 13:29 UTC
    I would like to print out a tab character between each element in the array

    There is a builtin special variable $":

    local $" = "\t"; my @a = qw(1 2 3); print "@a"; __END__ 1 2 3

    -- Frank

Re: printing out tabs between each element in an array
by Skeeve (Parson) on Feb 18, 2008 at 13:09 UTC
    You might want to look at the join command join "\t",@cols_for_row;

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: printing out tabs between each element in an array
by McDarren (Abbot) on Feb 18, 2008 at 13:11 UTC
    Indeed there is. You can use \t to represent a tab. So probably what you want is something like (untested):
    print ARRAY_CONTENTS join("\t", @cols_for_row), "\n";
    Update: added newline

    Cheers,
    Darren

Re: printing out tabs between each element in an array
by olus (Curate) on Feb 18, 2008 at 13:33 UTC

    You can set the output field separator to the tab character.

    $" = "\t"; print ARRAY_CONTENTS "@cols_for_row\n";

    Remember to restore the output field separator to its default value after you're done with the tab formating

      Remember to restore the output field separator to its default value after you're done with the tab formating

      One way to make it difficult to forget is to keep the localisation within the print statement by using a do block.

      print ARRAY_CONTENTS do { local $" = "\t"; "@cols_for_row\n"; };

      I hope this is of interest.

      Cheers,

      JohnGG

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: printing out tabs between each element in an array
by Anonymous Monk on Feb 19, 2008 at 00:57 UTC

    Win,

    I'd just like to offer my sincere congratulations on achieving 9 xp. That's almost 0.02 xp for every one of your 489 posts. We're all crossing our fingers on you making the 10 xp milestone.

    Best of luck!

    - A gutless coward

      Wow.... I was going to create a user profile; I've found help here a few times. You've scared that right out of me..... umm.... thanks?
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://668523]
Approved by Skeeve
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2021-12-07 17:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (34 votes). Check out past polls.

    Notices?