in reply to Why doesn't % interpolate?

Maybe it's tricky to find the right representation. Do you want just the keys? Just the values? Keys mixed with values? Does order matter?

Converting an array to a list is pretty sensical, but converting a hash to a list is a little different. (Think in terms of pairs.)

Replies are listed 'Best First'.
Re: Re: Why doesn't % interpolate?
by diotalevi (Canon) on Apr 18, 2003 at 19:55 UTC

    Oh dunno - we already have a definition for converting a hash to a list and an interpolated list array to a scalar. So I just wonder why a hash shouldn't interpolate as a list array. Perl5 doesn't have the same ideas about pairs that Perl6 does so at this point I'm not concerned about what to do with pairs because they don't exist.

      Lists don't interpolate. (How could they? They don't have names, let alone a sigil).

      There's limited value in having hashes interpolate directly; it's not as useful as interpolation of scalars and arrays. It would be very annoying though, as you would not be able to write

      printf "%d %s %f\n", $int, $str, $float;

      because that would try to interpolate three hashes.

      However, it's still relative simple to interpolate a hash:

      print "@{[%hash]}";

      Abigail

        Given

        my $s = 'foo'; my @a = 1..10; my $h = 1..10; print "${s} @{a}"; # gives "foo 12345678910"

        Is there anything that would conflict with print "%{h}"; from producing the same output as print "@{[ %h ]}";?