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

Thank you very much.

Just a question. Since I'm pretty new to Perl I cannot understand that "strange construct" in the while loop:

$text->{$line}[$pos - 1] = $word;

Please, can you give some more details on it?

Then here come the second question/problem. As far I can see keys are the original line numbers and values are references to arrays containing the words of each line. In that case, if I'm not in wrong, keys/lines do not respect the original order of my text. Is it true?

Replies are listed 'Best First'.
Re^3: Fetching data from DB and complex data structures
by AnomalousMonk (Archbishop) on Dec 14, 2015 at 16:59 UTC
Re^3: Fetching data from DB and complex data structures
by choroba (Cardinal) on Dec 14, 2015 at 22:11 UTC
    $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,
      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,