in reply to Complicated pattern match

Hi ,

my $A =~ s/[A-Z]/\|/g; my @values = split('\|',$A); map { if ($_ ne "" ) {print "[$_]\n";} } @values;

Replies are listed 'Best First'.
Re^2: Complicated pattern match
by Aristotle (Chancellor) on Jan 19, 2003 at 12:33 UTC

    No, that don't work. Your first line will substitue any A-Z character in $A with a pipe, which means all characters in this case since $A doesn't contain anything else. Then you split on pipes, which gets you a @values full of empty strings. Then you map in void context..

    If you leave out the substitution and split on nothing, it “works”:

    my @values = split //, $A; map { if ($_ ne "" ) {print "[$_]\n";} } @values;
    Except all it does is split $A into characters and print them on a line each. I have no idea how that is supposed to solve the poster's problem though, since it doesn't even look at $B. The if is superfluous as well, since every element of @values is guaranteed to contain one character from $A.

    Makeshifts last the longest.

      Hi,

      The code returns
      [xxxxxx] [yxxx] [zxxxx] [xxw]


      I guess the split converts only the caps in the $B and then I print the non_exmpty strings. Please let me know where I am totally wrong. I thought the $A was discontinuous, but the order of the characters remained the same and hence thought I could do it this way.
        Ah.. okay, I see what you were trying to do. The problem is that's not what the original poster needed - distinguishing by capitalization won't work for his real data set where instead of the wxyz there will be ACGT characters. So you have to try and find consecutive sequences out of $A in the right order inside $B, taking into account extra ACGT sequences in $B.

        Makeshifts last the longest.