Parse perl array

前端 未结 2 821
刺人心
刺人心 2021-01-27 06:14

I\'m not familiar with perl and am trying to edit an irssi translation script. The result from a web request returns as:

$result = {
 \"data\" => {
  \"transl         


        
2条回答
  •  独厮守ぢ
    2021-01-27 07:03

    "Halloween" could be obtained as:

    $result->{"data"}->{"translations"}->[0]->{"translatedText"}
    

    The arrows after the first one can be omitted, so an even shorter variant would be:

    $result->{"data"}{"translations"}[0]{"translatedText"}
    

    Basically you have multiple indirections at different levels:

    • reference to a hash
    • its "data" key being a reference to another hash
    • the "translations" key of the last hash being a reference to an array
    • the first element of that array is a reference to a hash
    • the "translatedText" key of that hash is a string

提交回复
热议问题