Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Printf : How to repeat characters?

by AnomalousMonk (Abbot)
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.


Comment on Re: Printf : How to repeat characters?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2015-05-24 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (472 votes), past polls