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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Set tab size

 



windx21
New User

Jan 31, 2010, 5:19 PM

Post #1 of 3 (3587 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


7stud
Enthusiast

Jan 31, 2010, 7:00 PM

Post #2 of 3 (3582 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.


Code
use strict; 
use warnings;
use 5.010;


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

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

say '123456789012345';
say $str;

--output:--
123456789012345
Hello world



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


shawnhcorey
Enthusiast


Feb 1, 2010, 6:15 AM

Post #3 of 3 (3568 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.

__END__

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

Perl documentation is available at perldoc.perl.org. 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