in reply to Re: simple regexp problem
in thread simple regexp problem

Sometimes you don't want to use split because it's too lenient! Your example will be happy to accept AAAA_BBBB_CCCC. The original poster probably wants this string to be rejected, but split will eat AAAA, BBBB, and discard CCCC.

Replies are listed 'Best First'.
Re^3: simple regexp problem
by jeffa (Bishop) on Dec 05, 2005 at 18:07 UTC

    Which is exactly why the original poster should be capturing the output into an array instead of multiple sequentially numbered scalars.

    I think split is a very good and acceptable solution for this problem.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re^3: simple regexp problem
by Tanktalus (Canon) on Dec 05, 2005 at 19:09 UTC

    In that case, split still works:

    my ($part1, $part2) = split /_/, $str, 2;
    That extra parameter asks for no more than two items - more _'s will not be even looked at.