in reply to How do I disable variable expansion of strings?

"For some reason this is not a problem for the % symbol which, I find inconsistent."

Hashes are not interpolated becuase they are not sequential objects. Using them in that way does not really make sense, although there are several work-arounds when you need it for debugging.

"Surely the same attempt at variable expansion would apply to all the primitives."
OK, except that a hash is not all that primitive. How would you expect a glob to be interpolated? The " operator can be overloaded, so you can change its behaviour if you need to. I get the feeling you need to read-up on interpolation, for example, in you main code:
print "Array entry: ". $i. "\t". $array[$i]. "\n";
Interpolated would be a bit nicer as:
print "Array entry: $i\t$array[$i]\n";

Replies are listed 'Best First'.
Re^2: How do I disable variable expansion of strings?
by ikegami (Patriarch) on Sep 03, 2007 at 17:06 UTC

    First you say it wouldn't be possible (Hashes are not interpolated becuase they are not sequential objects.), then you say it would be useless (Using them in that way does not really make sense). Both statements are false.

    The sequence changes when elements are added (or removed?), but that doesn't mean there isn't one. It would just as simple to support interpolation of hashes as it was to support interpolation of arrays.

    Some problems with implementing it at this point include backward compatibility and the possible resistance at adding another special variable (like $"), not a supposed lack of sequence.

    As for it being useless, that's untrue because I sometimes print the content of hashes without reordering them.

Re^2: How do I disable variable expansion of strings?
by seank (Acolyte) on Sep 04, 2007 at 10:28 UTC
    Perl Hashes look sequential to me, they look exactly like a specialised array with the the condition that it contains an even number of entries.

    #my %var = ('k1' => 'v1', 'k2' => 'v2'); my %var = ('k1', 'v1', 'k2','v2'); print $var{k2}. "\n";
    I now what interpolation means in other contexts, I'm not sure in relation to hashes.

    As tempting as it is to use the some of the convenient shortcuts of Perl (and I am aware of the one you're suggesting), I prefer to use explicit notation in all languages as a rule of thumb, its safer, clearer, and avoids potentially unintended behavious.

    Defining what the primitives are for a particular language is irrelevant to my original question, so I won't pursue it.