Getting many values in an array in perl

后端 未结 3 670
陌清茗
陌清茗 2021-01-23 19:36

I am writing a prel program in which I have an input file containing a pattern as:

FIELDS=(1,2,3,4)

OR

FIELDS=(1,10,3,A,11,10,7         


        
3条回答
  •  时光取名叫无心
    2021-01-23 19:47

    TIMTOWTDI. There is one of them:

    use strict;
    use warnings;
    
    while () {
        next unless /^FIELDS=\(([^)]*)\)/;
        my @fields = split ',', $1;
        while (@fields) {
            my @subfields = splice @fields, 0, 4;
            print "$. @subfields\n";
        }
    }
    
    __DATA__
    FIELDS=(1,2,3,4)
    FIELDS=(1,10,3,A,11,10,7,D,9,10,11,A)
    

提交回复
热议问题