I have the following code:
#!/usr/bin/perl
use strict;
use feature qw(say);
my $raw_text = "a b c d e f g h";
my @array = split(/ /, $raw_text);
my $element = @array[0];
say "Element [0] of array is : ", $array[0];
This prints on STDOUT:
Element [0] of array is : a
So far, so good. However if I want to retrieve the element straightforward from the split method, I would think of:
my $element = split(/ /, $raw_text)[0];
But it turns out that this throws a compilation error. Doing some research I figured out that I have to type:
my $element = ( split(/ /, $raw_text) )[0];
The question is: Why are the extra parenthesis necessary?
I might be missunderstanding the parenthesis meaning for this case.