I understand the complex structure. It is necessary to pull the data from the hash hashes. The moment that interests me looks like this:

print exists $v -> {'field'} -> {'code'} ? $v -> {'field'} -> {'code'} : 0; 

Gut feeling that you can cut this record, can anyone tell me how?

  • The removal of $v -> {'field'} before this in a separate variable does not count? - Regent
  • I see nothing strange. The context is clearly divorced from life and not driven through Devel :: NytProf. F furnace - PinkTux
  • @Regent, not exactly what you want. The structure is actually somewhat more complicated; parsing json is an example. - Pivoter
  • @Pivoter, so show the reality. But your goals and objectives are not clear. Maybe you have an architecture there that allows you to lie about a "write-only" pearl ... Or, for you, any structure with a couple of levels is complicated, so this is a completely different question. - PinkTux
  • @Pivoter is so even if it is more difficult, then you can still bring the entire chain to the variable except the last key. And about the function returnIfExistsOrZero I have not heard. - Regent

1 answer 1

 print $v -> {'field'} -> {'code'} // 0; 

operator // 0 - gives zero when left operand is undefined (undef)

  • one
    It is worth noting that // 0 is not a complete replacement for exists : it can be used only if the hash does not have values ​​equal to undef . - Regent