in reply to Re: Formating a printf statement using a variable
in thread Formating a printf statement using a variable

Why not simply so? printf "%-${print_size}s", $_;

Also note the lack of quotes around $_ - if you just refer to a variable by itself, don't interpolate it. There are cases where you need to do that, but you'll know them when you come across them. Most of the time it's just a wasted node in the optree and can even break code that would work fine without the quotes.

HTH

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: Formating a printf statement using a variable
by Marza (Vicar) on Jan 12, 2003 at 00:06 UTC

    Even better! Thank you! One less line and variable! I didn't know you could do that! ;-)

      Yep, very handy when you have something like my $type = $cond ? 'book' : 'module'; and want to print "books" or "modules": print "${type}s";. The straightforward print "$types"; will have strict complaining about an unknown $types.. although the curlies are very ugly extra linenoise, so in some cases (like this one) I'd prefer to say print $type . 's'; instead. But as with everything Perl: TMTOWTDI. :)

      Makeshifts last the longest.