How do parentheses work in Perl 5? -



How do parentheses work in Perl 5? -

here's devel::repl session (my perl version v5.10.1). explain results, please?

0:main$ $x = 1,2,4 [ 1, 2, 4 ] 0:main$ $y = (1,2,4) useless utilize of constant in void context @ (eval 296) line 8. 4

i'm origin learning perl , still have troubles grokking contexts. anyways, think understand why sec assignment does. that's because we've got scalar context, that's why no list constructed @ all, , end executing comma operator repeatedly, whilst opetator returns right operand. right?

however, what's wrong first assignment? shouldn't equivalent sec one? @ point, thought parentheses don't provide magic semantics build lists - grouping elements together, , if elements end beingness used in list context, transformed list. apparently, that's not true.

well, ok. special role of parentheses then?

devel::repl evaluating each input line in list context, , printing resultant list. first line like:

bring together ', ' => {my $x = 1, 2, 4}

which parsed as:

bring together ', ' => {(my $x = 1), (2), (4)}

and repl prints "1, 2, 4" since received 3 values do block.

the sec line is:

bring together ', ' => {my $x = (1, 2, 4)}

which parsed as:

bring together ', ' => {(my $x = scalar(1, 2, 4))}

the list in scalar context returns lastly element, assigned $x , returned do block, subsequently printing "4".

perl

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -