Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

Need to understand perl reference by clarifying these 4 patterns

I really really don't undertand perl hash. I have been reading perl doc but not able to completely get perl reference.

For a prime example, can you please tell me the difference between below?

 @{$table}{$item}
 @{$table{$item}}
 %{$table}{$item}
 %{$table{$item}}

Or is there some general rule that I am missing from not able to decipher these?

Please point me to right direction. I have been reading perldoc.perl.org..

question from:https://stackoverflow.com/questions/65648771/need-to-understand-perl-reference-by-clarifying-these-4-patterns

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just replace the reference-producing block ({ ... }) with an identifier to get a better sense of what you have.

  • @{$table}{$item}
    • Akin to @name{$item}
    • Array slice of the array referenced by $table
    • Can also be written as $table->@{$item}
    • There's no point to using a slice when there's only one item returned by the index expression. Should be ${$table}{$item} or $table->{$item}.
  • @{$table{$item}}
    • Akin to @name
    • Array referenced by $table{$item}
    • Can also be written as $table{$item}->@*
  • %{$table}{$item}
    • Akin to %name{$item}
    • Key-value hash slice of the hash referenced by $table
    • Can also be written as $table->%{$item}
  • %{$table{$item}}
    • Akin to %name
    • Hash referenced by $table{$item}
    • Can also be written as $table{$item}->%*

See


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...