Welcome to Rocteur Saturday, April 27 2024 @ 02:20 AM CEST
What purpose does the Unary + have ?from perldoc perlop Unary "+" has no effect whatsoever, even on strings. It is useful syntactically for separating a function name from a parenthesized expression that would otherwise be interpreted as the complete list of function arguments. Unary + has no effect on its argument (it doesn't even force scalar context on lists). It has at least three uses:
1. for anal people who have to say +123 to indicate that 123 is positive
2. to prevent parsing of a list as the sole arguments to a function without parenthesis, compare these: perl -le 'print (1, 2, 3, 4), " what are we fighting for"';
perl -le 'print +(5, 6, 7, 8), " open up the Perly gates"'; 3. since + is not part of the set of bareword characters it forces the parsing of a bareword as a function in hash indices -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read.
FAQ Manager » Perl » What purpose does the Unary + have ?
|