Parse perl array

雨燕双飞 提交于 2019-12-02 09:59:18

"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

That would be

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

$result is a hash ref. The key 'data' points at yet another hash ref, which has a key 'translations' pointing at an array ref. The first and only element in that array ref has a key 'translatedText' which points at the data of interest: 'Halloween'.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!