سؤال

I am working on some perl code that is not mine. I ran into this line and I have no idea what it is doing:

my $sum = [];

I just don't understand what this scalar is being set to.

هل كانت مفيدة؟

المحلول

[ LIST ]

is basically a shortcut for

do { my @anon = ( LIST ); \@anon }

It creates an array initialized with the result of the enclosed expression (if any), and returns a reference to that array.

نصائح أخرى

From the documentation:

If you write just [] , you get a new, empty anonymous array. If you write just {} , you get a new, empty anonymous hash.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top