Hi WK, On Sun, Sep 27, 2015 at 3:13 PM, WK <wanradt@gmail.com> wrote:
2015-09-27 14:48 GMT+03:00 Kadir Beyazlı <kadirbeyazli@gmail.com>:
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 dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Kadir Beyazlı Computer Engineer GSM : +90 535 821 50 00