Why is there a + symbol in front of the first left bracket in this Perl example?

I recently came across this statement

print +( map { $_ + 1 } @$_ ), "\n" for @$array; # <- AoA

I have not seen the operator +used with printing before . Performing the statement, it is not difficult to conclude what he is doing. But I find it difficult to find documentation for the operator +used in this way.

my @tab = (
[1,2,3,4],
[qw(a b c d)],
);

my $test = "(", +( map { qq( >>$_<< ) } @$_ ), ")\n" for @tab;
print $test;
my @test = "(", +( map { qq( >>$_<< ) } @$_ ), ")\n" for @tab;
print @test;
my %test = "(", +( map { qq( >>$_<< ) } @$_ ), ")\n" for @tab;
print %test;

A warning is issued above: Useless use of a constant ()) in void contextfor all three tests. Use of uninitialized valuefor the test scalarand Odd number of elements in hash assignmentfor the tests arrayand hash. It would be nice to save the output to scalar. I know that I can store an identical string in scalarusing a for loop, as shown below.

print "(", +( map { qq( >>$_<< ) } @$_ ), ")\n" for @tab;

my $out = '';
for (@tab) {
    $out .= "(" . ( join '', map { qq( >>$_<< ) } @$_ ) . ")\n";
}   
print $out;

# output ...
( >>1<<  >>2<<  >>3<<  >>4<< )
( >>a<<  >>b<<  >>c<<  >>d<< )
---
( >>1<<  >>2<<  >>3<<  >>4<< )
( >>a<<  >>b<<  >>c<<  >>d<< )

type. , print +.

. , , +, print, , , - for - ...

use strict;
use warnings;
my @a = ([1,2,3],[qw/a b c/]);
my $one = '';
$one .= "(" . ( join '', map { " >>$_<< " } @$_ ) . ")\n" for @a;
print $one;

# output ...
( >>1<<  >>2<<  >>3<< )
( >>a<<  >>b<<  >>c<< )
+4
2

, , , ... -, "+" , perlop

"+" . , .

, , perlmaven, .

, + ( perl, , . ​​

, , B:: Deparse, perl, :

print +(stat $filename)[7];

plus.pl perl -MO = Deparse plus.pl. :

print((stat $filename)[7]);

, !

Edit

, , , , ... , -, , , , , , perl docs :)

print "(", +( map { qq( >>$_<< ) } @$_ ), ")\n" for @tab;

perl

(print "(", +( map { qq( >>$_<< ) } @$_ ), ")\n") for @tab;

, , , @tab.

my $test = "(", +( map { qq( >>$_<< ) } @$_ ), ")\n" for @tab;

perl for @tab ")\n", Useless use of a constant ()) in void context . , , , for 'd

my $test; ( $test .= "(" . join ('', ( map { qq( >>$_<< ) } @$_)) . ")\n") for @tab; print $test;

, . "+" , .

+5

perldoc -f print:

,              ,                          ; ( "+",              ).

, map "\n", map { $_ + 1 } @$_. , , , + , +(map { $_ + 1 } @$_) (map { $_ + 1 } @$_), .

print ( map { $_ + 1 } @$_ ), "\n" for @$array;

, , . print , :

$ perl -we '$array=[[1,2,3]];print ( map { $_ + 1 } @$_ ), "\n" for @$array;'
print (...) interpreted as function at -e line 1.
Useless use of a constant ("\n") in void context at -e line 1.
234%

print. . print , "\n". , . , :

"\n" for @$array;

print.

, :

my $string;
$string .= sprintf( "(%s)\n", join('', map {$_ + 1} @$_) ) for @tab;
+4

All Articles