I am trying to decrypt a Perl code which I am not familiar with, in any way related to HashRef Amazon :: S3 I am using, but my question is a common Pearl question. See the code below:
use Amazon :: S3; My $ s3 = Amazon :: S3- & gt; new (...); My $ response = $ s3-> Bucket; Documentation (here) about sis, s3-> buckets:
Returns undefs of errors, other results are expunged The following line is working for me, but I do not understand that:
$ b ($ $ -> -> (buckets }}} {Print "Bucket:". $ B-> Bucket "\ N";}
I am upset by every operator on the first line.
Which type is exactly $ response , $ respone -> gt; {bucket} . It seems that < Expression is an array in code> for
, but I do not understand this syntax: @ {...} ?
Let's break it down.
$ s3 is your S3 object. $ S3-> Bucket calls the bucket method on that object, and we store the results in $ response docs, the result is a hash The references are; A reference is a scalar that points to another value. If you are familiar with pointers, then the idea is the same.
If we have a plain hash % response , then we can get it on the bucket the key in the hash $ response {bucket} by saying. Since we have a hash reference , we have to use the differential operator ( -> gt; ) to access the key, so that $ response- & Gt; {Bucket} .
But we have not been done yet. $ response-> {Bucket} is itself a reference, an array reference in this case. Here we are seeing any other dereferencing if we wanted to get only one item in the referenced array, for example, $ response-> gt; Can say {buckets} [0] . But we want complete list, so we use the @ operator to define the entire code. Since our array reference is included in a complex structure, we use debt to keep the expression in context. Then @ $ $ response-> gt; {Buckets}} makes us an array.
This is doing a whole lot in the same statement
To learn more about references, which is the most difficult to know in Perl
About array of arrays
Comments
Post a Comment