EchoAngel has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I been thinking hard and I'm not sure how to create a general pattern matching expression for these cases
direction : in code_unit : "1ps"; sum_1 ("0.01, 0.02"); function : "((( X1 | X2 ) & A1))"; process : 1; cap ( 3.0 , pf ); features ( display ) ;
what i would like are the following
direction , in code_unit , 1ps sum_1 , 0.01, 0.02 features , display process , 1 function , ((( X1 | X2 ) & A1)) cap , 3.0 , pf (exact text)
any help?

Replies are listed 'Best First'.
Re: Help with Generic Pattern Matching Statement
by artist (Parson) on Feb 14, 2005 at 22:22 UTC
    Go from here.
    while(<DATA>){ chomp; s/\"|\;//g; my($item,$value) = split /\s\:?/,$_,2; $value =~ s/^\s*\(//; $value =~ s/\)\s*$//; print "$item , $value\n"; } __DATA__ direction : in code_unit : "1ps"; sum_1 ("0.01, 0.02"); function : "((( X1 | X2 ) & A1))"; process : 1; cap ( 3.0 , pf ); features ( display ) ;
    Above gives
    direction ,  in
    code_unit ,  1ps
    sum_1 , 0.01, 0.02
    function , (( X1 | X2 ) & A1)
    process ,  1
    cap ,  3.0 , pf 
    features ,  display 
    
Re: Help with Generic Pattern Matching Statement
by Animator (Hermit) on Feb 14, 2005 at 21:35 UTC
    a) what have you tried so far?
    b) what exactly do you want to do? put the text in another format? or ...?
Re: Help with Generic Pattern Matching Statement
by holli (Abbot) on Feb 14, 2005 at 21:47 UTC
    I'm not sure how to create a general pattern matching expression for these cases
    When your text is to variant for creating a single regex, use more than one. Like:
    if ( /pattern1/ ) { do_stuff() } elsif ( /pattern1/ ) { do_stuff() } elsif ( /pattern3/ ) { do_stuff() } else { no_match() }


    holli, /regexed monk/