Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Printf : How to repeat characters?

by eyepopslikeamosquito (Chancellor)
on Oct 03, 2010 at 04:28 UTC ( #863138=note: print w/replies, xml ) Need Help??


in reply to Printf : How to repeat characters?

Does this do what you want?

my $a = chr(65); my $b = chr(66); my $c = chr(67); printf "%s" x 3, $a x 2, $b x 3, $c x 4;
Update: or perhaps this?
printf "%c" x 9, (65) x 2, (66) x 3, (67) x 4;
or even, using james2vegas' "$" idea, but with %c instead of %s
printf '%1$c'x2 . '%2$c'x3 . '%3$c'x4, 65, 66, 67;
BTW, the above strange-looking POSIX extension positional parameter $ printf syntax was introduced in Perl 5.8 in 2002.

Replies are listed 'Best First'.
Re^2: Printf : How to repeat characters?
by westrock2000 (Beadle) on Oct 03, 2010 at 04:34 UTC
    yep works perfect....the %s made all the difference :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://863138]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-10-22 07:25 GMTServer Error (Error ID 8359050c38790)

An error has occurred. The site administrators have been notified of the problem and will likely soon fix it. We thank you, for you're patients.

Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (272 votes). Check out past polls.

    Notices?