in reply to simple regexp problem

how about
my ($part1, $part2) = split /_/, $str;

Replies are listed 'Best First'.
Re^2: simple regexp problem
by Celada (Monk) on Dec 05, 2005 at 17:41 UTC

    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.

      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)
      

      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.