in reply to Making a variable tab string

You have the canonical answer from jwkrahn. However your code indicates a few opportunities for learning.

First off always use strictures (use strict; use warnings;).

Perl programers seldom use a C style for. The more usual way to iterate a fixed number of times is:

for my $index (1 .. $numTabs) { ... }

Although in the case in hand you don't need the counter at all. You could just:

for (1 .. $numTabs) { ... }

and if there is only one simple statement in the loop you can use the for as a modifier:

... for 1 .. $numTabs;

I suspect there is a transcription error in your sample code. Most likely what you intended was:

$tabs = "$tabs\t";

in which case Perl allows you to use the concatenation assignment operator:

$tabs .= "\t";

so a more Perlish technique (without using the x operator) is

$tabs .= "\t" for 1 .. $numTabs;

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Making a variable tab string
by sandrider (Acolyte) on Feb 22, 2007 at 00:07 UTC
    Cool. Thanks a lot.