Getting many values in an array in perl

后端 未结 3 644
陌清茗
陌清茗 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:39

    You can use split to break you comma separated matches into individual pieces:

    use strict; 
    use warnings; 
    
    my $line = 'FIELDS=(1,10,3,A,11,10,7,D,9,10,11,A)'
    
    if ( my ($fields) = $line =~ /FIELDS=(\(.*\))/ ) {
       my @vars = split /,/, $fields; 
       # do whatever you want with @vars
    }
    

提交回复
热议问题