• Commented on A small puzzle for you
    #!/usr/bin/env perl use strict; use warnings; use List::AllUtils 'uniq'; use Data::Printer; sub align { my @all_values = sort(uniq(map {@$_} @_)); for my $param (@_) { my %hash;@hash{@$param}=@$param; @$param = @hash{@all_values}; } return; } my @a = ( 'b', 'c',...
  • Commented on I hate Dist::Zilla and missing Makefile.PL
    Yep. That's why I use the Git::CommitBuild plugin, to give you both (what I write) and (what you can use without dzil). This way, anyone can send me patches for whichever version they're most confortable with, and I...
  • Commented on Keeping a Reasonable Number of Incremental Backups
    That looks very much like I've been using it for years and it's very very simple....
  • Commented on I try postderef and key-value slice in Perl 5.19.5
    That's not the way ->%{} is supposed to work. $a->%{foo} returns foo => $a->{foo}, and you can't assign to such a thing. You probably meant $new_params->@{'FOO', 'BAR'} = $params->@{'foo', 'bar'};, which does the assignment you're looking for....
  • Commented on A feed reader
    It would not be particularly complicated to get Feeder to send email instead of writing to a maildir: you just write a role to do that. It would be like Feed::Role::MailDir, but instead of using Maildir::Lite, it would directly send...
Subscribe to feed Recent Actions from dakkar

  • E. Choroba commented on A small puzzle for you
  • Aristotle commented on A small puzzle for you
    my ( $i, %index ) = 0;
    $index{ $_ } //= $i++ for @a, @b, @c;
    for ( \( @a, @b, @c ) ) {
        my @rearranged;
        @rearranged[ @index{ @$_ } ] = @$_;
        $#rearranged = keys %index;
        @$_ = @$rearranged;

    Untested. Downside is the double copy.

  • Aristotle commented on A small puzzle for you

    I believe it takes linear time in the length of the inputs, while they take order (n log n).

    That would be nice if this were C, but it’s Perl. So the algorithm may be linear, but due to huge amounts of op dispatch, sub call overhead etc, its implementation in Perl likely has a humongous constant factor, which a big-O analysis hides. In order to actually see it outrun the algorithms that are worse in big-O terms, you’ll probably have to feed it inputs on the order of six digits, maybe even seven or more.

    Optimising Perl code usually means finding a…

  • tlrrd commented on A small puzzle for you
    use warnings;
    use List::MoreUtils qw(uniq);
    my @in = (
        [ 'b', 'c', 'f' ],
        [ 'a', 'd'      ],
        [ 'c', 'd', 'e' ],
    my $i =0;
    my %indexes = map {$_ => $i++} sort uniq map @$_, @in;
    foreach $r (@in) {
      my @new;
      @new[$i-1,@indexes{@$r}] = (undef,@$r);
      $r = \@new
    use Data::Dumper;
    print Dumper \@in;

    Not sure if it had to be in place or sorted, but I believe this works.

    With apologies to Moritz, whose framework I stole. I would have used Aristotle's uniq replacement, but $work perl is only 5.10.1

  • pru-mike commented on A small puzzle for you

    Yet another solution

Subscribe to feed Responses to Comments from dakkar

About is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is hosted by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.