Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Printf : How to repeat characters?

by AnomalousMonk (Canon)
on Oct 03, 2010 at 06:01 UTC ( #863147=note: print w/replies, xml ) Need Help??

in reply to Printf : How to repeat characters?

Here's another approach that allows ordinary strings, formatted pairs, and formatted pairs with repeat counts to be freely intermixed. Not extensively tested, but seems to work with fair variety of things I've tried, and both with and without file handles. (The prototype is only needed if the function is defined after the point of invocation.) Note: Needs 5.10 for  // operator – easily replaced.

>perl -wMstrict -le "sub fmtx (@); ; print STDERR fmtx [ '%3.6f', 1.23, 3 ], '---', [ '%0x', 10 ], [ '%s', 'hi', 4 ], qq{that's all, folks \n}, ; ; sub fmtx (@) { map ref() ? sprintf($_->[0],$_->[1]) x ($_->[2] // 1) : $_, @_ } " 2> fmtx_stderr >cat fmtx_stderr 1.2300001.2300001.230000---ahihihihithat's all, folks

Update: Original example code did not actually work! Fixed – as far as I can tell. Caveat Programor.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://863147]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2016-10-26 08:34 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (337 votes). Check out past polls.