Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

•Re: peek - output a one-line preview of stdin

by merlyn (Sage)
on Apr 27, 2003 at 20:40 UTC ( #253528=note: print w/replies, xml ) Need Help??


in reply to peek - output a one-line preview of stdin

my $pad = ' ' x $wide; ... $_ = substr($_ . $pad, 0, $wide); print $_, "\r";
That can be written far more simply and efficiently as:
printf "%-${wide}.${wide}s\r", $_;

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: peek - use printf
by halley (Prior) on Apr 28, 2003 at 02:58 UTC
    Great tip-- I often forget to use printf, as if moving from C to Perl meant having to leave all of C's methods behind. I have never liked the %#.#s notation of printf... and now I imagine perl6's interpolated hashes may make for some righteous DWIM hacks.

    --
    [ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2023-03-31 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (75 votes). Check out past polls.

    Notices?