Split a string into array in Perl

后端 未结 5 1836
清歌不尽
清歌不尽 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:11

    I found this one to be very simple!

    my $line = "file1.gz file2.gz file3.gz";
    
    my @abc =  ($line =~ /(\w+[.]\w+)/g);
    
    print $abc[0],"\n";
    print $abc[1],"\n";
    print $abc[2],"\n";
    

    output:

    file1.gz 
    file2.gz 
    file3.gz
    

    Here take a look at this tutorial to find more on Perl regular expression and scroll down to More matching section.

提交回复
热议问题