Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • So what was the problem and the solution and the explanation for why it works?
    --
    Bill
    # I had a sig when sigs were cool
    use Sig;
    • It had to do with alternation and backtracking. We were matching any consecutive nonwhitespace chars, and treating HTML entities as single chars, for the purpose of counting (we were breaking up strings of $n chars) and to make sure we don't split in the middle of the entities. So something like this (simplified):
      $foo =~ /\G (( &\w+; | \S ){$n}) /gx;
      Consider $foo = 'abc&' and $n = 3. I would want 'abc' to match, and '&' to not match, since it is not 3 chars long. '&am' matches, but I don't want it to to match. So how to make it not match?

      I added negative lookahead:
      $foo =~ /\G (( &\w+; | (?!&\w+;)\S ){$n}) /gx;
      This way, when it backtracks after the &\w+; fails, it will try to proceed with \S, but fail because the lookahead sees the '&'.

      It's not the most complicated thing, but sometimes we have mental blocks ... and bathrooms are where you relieve blockages ... (sorry :)