Split a string into array in Perl

后端 未结 5 1854
清歌不尽
清歌不尽 2021-02-06 00:24
my $line = \"file1.gz file2.gz file3.gz\";
my @abc = split(\'\', $line);
print \"@abc\\n\";

Expected output:

file1.gz
file2.gz
file3.gz         


        
5条回答
  •  渐次进展
    2021-02-06 01:10

    Just use /\s+/ against '' as a splitter. In this case all "extra" blanks were removed. Usually this particular behaviour is required. So, in you case it will be:

    my $line = "file1.gz file1.gz file3.gz";
    my @abc = split(/\s+/, $line);
    

提交回复
热议问题