Let's say there is a class called 'SF' which is conceptually just a string plus a list of values. Concatenation on two SF objects works by concatenating the strings and concatenating the lists. For example:
$x = new SF("?", ["foo"]);
$y = new SF(",?", ["bar"]);
$x . $y is an SF object with string "?,?" and list ["foo", "bar"]
Ordinary strings have an obvious representation as SF objects by setting the list to the empty list, e.g.
"blather" <-> new SF("blather", []);
Suppose that we have an SF-object $name. What I would like to happen is when perl encountered an interpolated string like:
"Hello, $name"that somehow the following transformations would occur:
"Hello, $name" -> "Hello, " . $name
-> new SF("Hello", []) . $name
-> concatenation of two SF objects
In a sense, instead of stringifing $name, the other string would get SF-ified.
Any ideas of if this can be done in either perl5 or perl6?
In reply to redefining string interpolation by perl5ever
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |