Hi Niels, On Sun, Sep 27, 2015 at 3:37 PM, Niels Larsen <[email protected]> wrote: > Kadir, > > This will keep hash order, > > http://search.cpan.org/~chorny/Tie-IxHash-1.23/lib/Tie/IxHash.pm > > I only use it when I have to, but there is not too much of a > slowdown, and I would guess your hashes are small anyway. > I don't use Dancer myself, but follow its progress. [KB] Thanks, the solution Dave offered works at template toolkit also. > Niels L > > > > On Sun, 2015-09-27 at 15:30 +0300, Kadir Beyazlı wrote: >> Hi WK, >> >> On Sun, Sep 27, 2015 at 3:13 PM, WK <[email protected]> wrote: >> > 2015-09-27 14:48 GMT+03:00 Kadir Beyazlı <[email protected]>: >> > >> >>> Of course, I can't be sure until I know what your data structure really >> >>> looks like, >> >> [KB] The data Richard mentioned is a classic fetchall_hashref data as >> >> below: >> >> >> >> $Pats = {ID => { SNAME => Value, >> >> CHNAME => Value, >> >> ANAME => Value, >> >> }, >> >> ID => { SNAME => Value, >> >> CHNAME => Value, >> >> ANAME => Value, >> >> }, >> >> ID => { SNAME => Value, >> >> CHNAME => Value, >> >> ANAME => Value, >> >> } >> >> } >> > >> > When we need those elements be in particular order, sorted by any >> > deeper value in hash tree, there is two main solutions for this goal. >> > >> > First (and best for me). As hash can't maintain an order of elements, >> > you provide different data structure in right order, namely arrayref, >> > something like: >> [KB] I always use array ref if I need to order a database data because >> hash is unordered as you wrote and sort function sorts by key not by >> vaue (At perl code, it also sorts by value) at template toolkit. I >> tried to explain data structure Richard has trouble to Dave because >> Dave wrote a solution >> >> Richard, >> >> I offer you using arrayref at template toolkit too. Template toolkit >> supplies reaching values by table column names unlike perl code (t >> Perl code, we ave to use index to reach array data) which is very >> useful >> > $Pats = [ { 123 => { SNAME => Value, >> > CHNAME => Value, >> > ANAME => Value, >> > } }, >> > { 124 => { SNAME => Value, >> > CHNAME => Value, >> > ANAME => Value, >> > } }, >> > { 125 => { SNAME => Value, >> > CHNAME => Value, >> > ANAME => Value, >> > } >> > } ]; >> > >> > Other variant is to use some helper in your templating system, which >> > provides map/reduce (Schwarzian transform) functionality. So you can >> > feed in your hash and it gives back id-s in specified order. >> > >> > Hope it helps. >> > >> > Wbr, >> > -- >> > Kõike hääd, >> > >> > G >> > _______________________________________________ >> > dancer-users mailing list >> > [email protected] >> > http://lists.preshweb.co.uk/mailman/listinfo/dancer-users >> >> >> > > _______________________________________________ > dancer-users mailing list > [email protected] > http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Kadir Beyazlı Computer Engineer GSM : +90 535 821 50 00 _______________________________________________ dancer-users mailing list [email protected] http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
