Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • my %hash;
    %hash{@array} = 1 xx @array;

    Actually I like that better than the map, but I agree it sucks that the map version doesn't work right now.

    • I think I like it better too. Just gotta internalize it :)

      Hm, once laziness is in place, one could even do '1 xx *'. That pleases me.

      • Some variation on this ought to work:

        my %hash = @array X 1;

        That would seem like the most direct expression of what one wants.

        But I can’t quite figure out the right incantation.

        • This should work indeed, but currently suffers from a lack of list flattening in Rakudo. Specifically

          my @a = <a b c>;
          say (@a X 1).perl; # ("a", 1, "b", 1, "c", 1)
          say (@a X 1).elems; # 3

          And then the hash assignment complains about an odd number of elements.

          One can explictly construct Pair objects though:

          my %h = @a X=> 1;
          say %h.perl; # {"a" => 1, "b" => 1, "c" => 1}

          Which is maybe a bit prettier than colomon's solution, but we can argue about that :-)

    • what's the matter with %hash = @array >>=>>> 1 ? (might not work with texas hyper, but does with the normal hyper.)