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

后端 未结 8 1875
时光说笑
时光说笑 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:53

    Your code sample is missing an s in the match operator. Other than that, it worked fine for me:

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

    Output is:

    a
    b
    c
    

提交回复
热议问题