Perl: array reference versus anonymous array

后端 未结 3 1950
无人及你
无人及你 2021-01-12 06:08

This may be a silly question... The following code outputs the contents of @arrayref and @arraycont respectively. Note the difference between them

3条回答
  •  有刺的猬
    2021-01-12 06:59

    The first block stores the address of @array. REferences are like 'live streaming', you get current status. So if you create a reference to @array, like \@array, when you de-reference it you will always get what @array points at the moment of de-reference. When you de-refer @array was having (5 6 7 8)

    When you do [@array] its like recording the live streaming into your disk. So when you (re)play the recorded content you get what was streamed at the time of recording. So when you refer $arraycont[0] you get what @array was having at the time of copying that is
    (1 2 3 4)

提交回复
热议问题