Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: printf question

by RMGir (Prior)
on Jan 21, 2010 at 12:53 UTC ( #818707=note: print w/ replies, xml ) Need Help??


in reply to Re: printf question
in thread printf question

almut's right.

You can get a slight improvement by keeping track of your longest word as you count them, though, and then using printf's "*" modifier to read the field width from that variable.

printf "%-*s %d\n", $maxLen, $word, $seen{$word};
I'd put a width specifier on the %d so the numbers line up nicely as well, but that's just my preference:
printf "%-*s %4d\n", $maxLen, $word, $seen{$word};

Mike


Comment on Re^2: printf question
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-12-22 06:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (111 votes), past polls