Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do square brackets do in Perl?

Tags:

literals

perl

I'm confused with the usage of square bracketed comma delimited elements in perl:

[short($file), -s $file];

Can somebody tell me what does this code mean?

like image 373
e19293001 Avatar asked Nov 26 '12 13:11

e19293001


2 Answers

[] creates an array reference.

[ $scalar, $scalar ] creates an array reference with two items in it.

short($file) calls a subroutine and returns something (probably a scalar or a list of scalars)

-s $file gives you the size of the file (as a scalar).

[short($file), -s $file] gives you an array ref containing the above two things.

like image 98
Quentin Avatar answered Oct 10 '22 16:10

Quentin


It creates a reference to an array with two items, the result of a function call to short($file) and the size of the $file.

like image 38
Moritz Bunkus Avatar answered Oct 10 '22 16:10

Moritz Bunkus