Perl: the Markov chain saw | |
PerlMonks |
Re: Dividing and formatby davido (Cardinal) |
on Nov 27, 2003 at 17:42 UTC ( [id://310565]=note: print w/replies, xml ) | Need Help?? |
As others have mentioned, the obvious answer is to use sprintf as follows:
But for no good reason I started thinking, hmm, what if we lived in some wierd world where sprintf didn't exist, but printf did? One could write his own sprintf function by hand. But that's not nearly as fun as abusing Perl 5.8.0 (or later):
This method doesn't meet the OP's spec, because it uses printf. But I couldn't resist an opportunity to write to an in-memory file (held in a scalar, $string) and then turn around and use it as a plain old scalar later. I dare you to turn that one in to the teacher. ;)
Update: Added 'require 5.8.0;' to my snippet to protect people who might otherwise ignore my suggestion that this is only a Perl 5.8.0 or later solution. Dave "If I had my life to live over again, I'd be a plumber." -- Albert Einstein
In Section
Seekers of Perl Wisdom
|
|