There's this hype about overloading, but I find it a bit scary. I don't really know why, but I'd rather use some technique that allows interpolation of any data.
When you're no longer talking about having a simple scalar, but about interpolating a function call, it's easy to find in
perlfaq, under
How do I expand function calls in a string?:
This is documented in perlref. In general, this
is fraught with quoting and readability problems,
but it is possible. To interpolate a subroutine
call (in list context) into a string:
print "My sub returned @{[mysub(1,2,3)]} that time.\n";
If you prefer scalar context, similar chicanery is
also useful for arbitrary expressions:
print "That yields ${\($n + 5)} widgets\n";
Version 5.004 of Perl had a bug that gave list
context to the expression in "${...}", but this is
fixed in version 5.005.
So, you could try:
print "Your order is for $count donuts which are specified with ${\ $d
+onut->printed }<BR><BR>\n";
If you need list context, you'd use
@{[]}, but
${\ join ' ', ...} is a LOT faster (you could use
$" to join with, but that's a bit slower, and it's probably a single space anyway).
Another solution would be using
printf:
printf("Your order for %d donuts which are specified with %s<BR><BR>\n
+", $count, $donut->printed);
HTH
++ vs lbh qrpbqrq guvf hfvat n ge va Crey :)
Nabgure bar vs lbh qvq fb jvgubhg ernqvat n znahny svefg.
-- vs lbh hfrq OFQ pnrfne ;)
- Whreq
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.