Can somebody explain it for me why the resulte of the code is 'ef'.
I just don't understand the @{[pop @a]} mean.
@a=('a', 'b' , 'cd' , 'ef');
print @{[pop @a]}, "\n";
If you don't understand a complex idiom in a programming language it
usually helps to break it into little parts (reading from the inside
out):
pop @a you should understand. If not, read perldoc -f pop.
[ ... ] constructs an anonymous array and returns a reference to it.
@{ ... } dereferences a reference to an array. (both are explained in
perlref and perlreftut)
So in this case @{[ ... ]} is rather superfluous, since you end up with
a copy of the list you started with, giving you the same output as if you
had written
print pop @a, "\n";
in the first place.
The @{[ ... ]} construct can be used to embed arbitrary perl expressions
into a double-quoted string:
print "the last element was @{[pop @a]} but now it isn't any more\n";
hp