Why can't I have a literal list list right after printing in Perl?

I see that I can do something like this:

print STDOUT (split /\./, 'www.stackoverflow.com')[1];

and "stackoverflow". However, this:

print +(split /\./, 'www.stackoverflow.com')[1];

does the same thing and this:

print (split /\./, 'www.stackoverflow.com')[1];

is a syntax error. So what is going on here? I always understood the sign of the unary plus, so as not to do anything in any context. And if "print FILEHANDLE EXPR" works, I would suggest that "print EXPR" will always work equally well. Any ideas?

+3
source share
2 answers

You have no warnings. In the case, a print(...)[1]set of parentheses is considered as part of the function syntax.

print (...) interpreted as function at C: \ Temp \ t.pl line 4.

, perldoc -f print:

, , , print — a + .

. Perl ?

+16

perldoc print :

, , - "+" .

print LIST.

print (split /\./, 'www.stackoverflow.com')

.

print (split /\./, 'www.stackoverflow.com')[0]

LIST , (, , LIST , ). [0] , .

print "abc","def";       # prints "abcdef"
print ("abc","def");     # prints "abcdef"
print ("abc"), "def";    # prints "abc"


Perl, , :

warn ($message),"\n"   # \n not passed to warn, line # info not suppressed

system ("echo"),"x"    # not same as system("echo","x") or system "echo","x"
                       #    or system(("echo"),"x")
+8

Source: https://habr.com/ru/post/1722037/


All Articles