Why is the list my Perl map returns just 1's?

后端 未结 8 1913
时光说笑
时光说笑 2021-01-02 07:32

The code I wrote is as below :

#!/usr/bin/perl 

my @input = ( \"a.txt\" , \"b.txt\" , \"c.txt\" ) ;
my @output = map { $_ =~ s/\\..*$// } @input ;

print @o         


        
8条回答
  •  没有蜡笔的小新
    2021-01-02 07:56

    As mentioned, s/// returns the number of substitutions performed, and map returns the last expression evaluated from each iteration, so your map returns all 1's. One way to accomplish what you want is:

    s/\..*$// for my @output = @input;
    

    Another way is to use Filter from Algorithm::Loops

提交回复
热议问题