in reply to Re^2: Fetching data from DB and complex data structures
in thread Fetching data from DB and complex data structures

$text->{$line}[$pos - 1] = $word; ^ ^ ^ | | | | hash | dereference array

I used $pos - 1 as positions start from 1, but array indices start from 0.

Note that the bracket types are the same as when creating the data:

$VAR1 = { 'c3' => [ 'Phasellus', 'non', 'erat' ], 'b2' => [ 'consectetuer', 'adipiscing', 'elit.' ], 'a1' => [ 'Lorem', 'ipsum', 'dolor', 'sit', 'amet,' ] };
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^4: Fetching data from DB and complex data structures
by frasco (Beadle) on Dec 15, 2015 at 11:51 UTC
    Thank you very much for the links and for the fish as well. If i can, what about the original order of the text? a1->b2->c3? Unfortunately, since the lines are indexed in a more complicated fashion than the one I reported, I cannot simply sort hash keys. In fact the original order is governed by Postgres only.
      the original order is governed by Postgres only
      That is a very bad design. See the documentation:
      If sorting is not chosen, the rows will be returned in an unspecified order. The actual order in that case will depend on the scan and join plan types and the order on disk, but it must not be relied on. A particular output ordering can only be guaranteed if the sort step is explicitly chosen.
      If you don't want to build a hash, use an array.
      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
        Sorry, I mean that the order is governed by the ORDER BY clause of Postgres, thus data retrieved from postgres of course are ordered correctly. I only mean that I have to rely on that order and I cannot sort the keys of the hashref.