develooper Front page | perl.perl5.porters | Postings from June 2015

Re: scalar sort $scalar

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
June 28, 2015 09:11
Subject:
Re: scalar sort $scalar
Message ID:
20150628111047.6037ae0b@pc09.procura.nl
On Sun, 28 Jun 2015 09:56:21 +0100, Zefram <zefram@fysh.org> wrote:

> H.Merijn Brand wrote:
> >That could easily be transformed into producing
> >$ perl -wE'say scalar sort "bdca"'
> >abcd
> 
> YAGNI.

Oh, but I did, which is why I wondered

Someone needed a selection for all possible combinations (permutations)
of letters in a sequence of letters, so I ended up with this instead

    my $alt = join "" => sort split m// => $code;

to map all possible combinations into a single alt code and use that in
a hash. Works great. The code did not need *all* possible permutations,
just look at all existing permutations in a reference table.


my %ref = (
   acb => 1,
   axf => 3,
   bca => 2,
   cab => 3,
   cde => 2,
   fxa => 0,
   );

I get the code "abc" and want to visit all entries in the hash where
the letter combination is the same, regardless the order. I revamped
the hash to add an extra layer

my %ref = (
    abc => {
        acb => 1,
        bca => 2,
        cab => 3,
        },
    afx => {
        axf => 3,
        fxa => 0,
        },
    cde => {
        cde => 2,
        },
    );

see the need?

> -zefram


-- 
H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.21   porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/        http://www.test-smoke.org/
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About