There is no limit to the number of captured substrings that you may use. However Perl also uses \10, \11, etc. as aliases for \010, \011, etc. (Recall that 0 means octal, so \011 is the character at number 9 in your coded character set; which would be the 10th character, a horizontal tab under ASCII.) Perl resolves this ambiguity by interpreting \10 as a backreference only if at least 10 left parentheses have opened before it. Likewise \11 is a backreference only if at least 11 left parentheses have opened before it. And so on. \1 through \9 are always interpreted as backreferences.
I think such a behaviour should be also possible for hash interpolation. We could chosse not to interpolate %i, %d, ..., but interpolate all non used formats from printf like %hash, ... . (Most of the %i, %d, ... aren't even good names for hashes, and the most sensful abbreviation for a hash %h isn't blocked by printf). Another way could be to interpolate %i, %d, ... only if there is such a hash defined. And even as also %llf can be a valid name, when working with quads, it's not that big problem. (Especially as such ambigious situations could be detected by the warning pragma)Of course, it is an argument, that it is hard for Perl to find out what a kind of interpolation makes sense for the user. I would guess it would be key1=>value1,key2=>value2,.... However, it should be not difficult to customize this behaviour like it is already done for arrays with the $" variable. We only need a variable specifying the seperator between key and value ("=>"), between elements (","), and whether you want to see keys, values or both. The only disappointing fact to this idea is that the $% variable is already forgiven :-(
I cannot imagine that it is so hard to implement. Perhaps it's an idea to bundle it in Perl 5.10. I would find it as a real cool feature and free us from using Data::Dumper or similar. Especially in 1-4 liners, it's frustrating to type so much sensless chars, only to print a hash!
Greetings,
Janek
PS: I didn't post this message already in april, as I've been not on perlmonks in april :-(
In reply to Re: Re: Re: Re: Why doesn't % interpolate?
by bigj
in thread Why doesn't % interpolate?
by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |