CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Set tab size


New User

Jan 31, 2010, 5:19 PM

Post #1 of 3 (6610 views)
Set tab size Can't Post

How can i set the tab size of print in perl
For example: print "Hello\t world".
This will result in "Hello World" with 8 spacing. I want to change the tab to 4 space

Millon of thankSmile


Jan 31, 2010, 7:00 PM

Post #2 of 3 (6605 views)
Re: [windx21] Set tab size [In reply to] Can't Post

I think the number of spaces in a tab is set by the user, i.e. it's system dependent. Whether perl is able to change the system's setting, I don't know. But I'm left wondering why anything like that would be necessary when you can write one line of perl code to replace the tabs in a string with four spaces.

use strict; 
use warnings;
use 5.010;

my $str = "Hello\tworld";
my $replacement = ' ' x 4;

$str =~ s/\t/$replacement/;

say '123456789012345';
say $str;

Hello world

(This post was edited by 7stud on Jan 31, 2010, 7:20 PM)


Feb 1, 2010, 6:15 AM

Post #3 of 3 (6591 views)
Re: [windx21] Set tab size [In reply to] Can't Post

There is a standard module Text::Tabs for expanding tabs. See `perldoc Text::Tabs`.

For a complete list of standard modules and pragmatics, see `perldoc perlmodlib`. All standard modules and pragmatics should be installed with Perl. If not, you can download them from CPAN.


I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives