>
> On 2013-05-06 19:51, John Black <
jbl...@nospam.com> wrote:
> > Hopefully a simple question...
> >
> > Given this printf that specifies some fixed length left justified columns:
> >
> > printf "%-30s, %-30s, %-30s\n", $a, $b, $c;
> >
> > How can I make the hardcoded number 30 use a variable, say $len instead?
> >
> > This does not work:
> >
> > printf "%-$lens, %-$lens, %-lens\n", $a, $b, $c;
> >
> > I'm guessing because perl would have trouble knowing that the s at the
> > end is not part of the variable?
>
> Yes.
>
> Either:
>
> printf "%-${len}s, %-${len}s, %-${len}s\n", $a, $b, $c;
>
> Or (more C-like):
>
> printf "%-*s, %-*s, %-*s\n", $len, $a, $len, $b, $len, $c;
>
> hp
Thanks much. I guess with Perl, its probably going to be adding either {}, [] or ().