in reply to Re: while loop logic
in thread while loop logic

This is exactly the sort of situation for which a flip-flop is intended:
while( <CMDTXTF> ) { my @fld = split /\|/, $_; print "$fld[0] $fld[2] sequence=$fld[4] $fld[5]" if /$regex/ and not (($fld[5] =~ m{ /\* }x)..($fld[5] =~ m{ \*/ }x +)); }

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^3: while loop logic
by Anonymous Monk on Jan 16, 2006 at 09:47 UTC
    I've tried out all the solution suggested in this post but there's still one problem I'm struggling to cope with. It transpires that whilst ignoring data between comments there are some cases where I need to run the regexp against what's left of the data in the record after the comments have been stripped e.g.
    asdfgh|kjkhg|poioiu|ytr|kkk|aaa /* vbfew */ kkkwwwqqqsss
    In this case the comment is complete within the record but I still need to check the rest of the record (aaa kkkwwwqqqsss) for any regexp matches.
    In fact this issue applies throught the data sets I'm trying to deal with. It was my mistake in not explaining this properly when asking for assistance. Which by the way has been excellent.

      This seems to handle both the scenarios you've outlined

      #! perl -slw use strict; while( <DATA> ) { chomp; if( m[/\*] ) { $_ .= <DATA> until m[\*/]; s[\s?/\* .+? \*/\s?][]smg; } print join '-', split '\|'; }

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Sadly it doesn't. I'm not sure if things are complicated by the fact that the text field can contain asteris that are not considered part of a comment e.g.
        case1 aaa|bbb|ccc|ddd|eee|fff * hhh /*xyzxyz*/ abc or case2 aaa|bbb|ccc|ddd|eee|fff * hhh /*xyz sss|ddd|ggg|hhh|jjj|xyz*/ abc or case3 aaa|bbb|ccc|ddd|eee|fff * hhh /*xyz jjj|kkk|lll|ppp|ooo|blah blah blah sss|ddd|ggg|hhh|jjj|xyz*/ abc
        Sometimes the comment block is in the same record, at other times it spans 1 or more records. So in the example I would still need to check (fff * hhh and abc ) to see if they met my pattern match (becuase they're outside the comment block. Having had only limited Perl exposure this is really taxing me.