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.
  • In one of his talks (Enterprise Perl?) James Duncan discussed readable code and gives the excellent advice that every loop should be a method. I find myself doing this more with Java than Perl, probably because I hit the mental ceiling for method length with Java's verbosity. So I'd typically translate your example to a method like:

    skipUnopenedTags(theStack);

    One side-effect of Java's not having unless is that I tend to write both 'isSomething' and 'isNotSomething' for readability, especially because an

    • I think that might be the case sometimes. I also think that there are people that just don't care. I've asked someone at work why they wrote this:
      my$x=$test>5?'foo':'bar';

      vs

      my $x = $test > 5 ? 'foo' : 'bar';

      And they literally didn't see the difference. It's quite depressing.

      -Dom

  • In a similar application, I keep a hash of open tags along with a stack. This is a simple ++/-- thing, but it makes the given snippet even more readable:
    return unless $tags{$tag};
    (literal paste)
  • Can you please explain, maybe show an example, of what you mean with step 3? It's just a mystery to me now.
    If this tag cannot be placed under any tags in the stack of open tags, look for a tag in the stack that contain this tag's nominal parent. Remember this tag, and repeat the process with this tag's parent.

    Do you mean to say that if you find a <LI> tag without an enclosing <UL> or <OL> , you insert one of those?

    • Right.

      If <LI> cannot fit within the current open tag (such as <A>), walk up the stack of open tags until you can find a spot where you can open it. If, for example, you find an open <OL>, close all open tags until the <OL> is at the top of the stack. (Presumably, that means you forgot a </LI> somewhere, since they cannot nest.)

      If there is no spot in the stack where you can deform it to open a <LI> tag, try to open the sequence <OL> <LI>, and find the cl

  • The single statement Perl equivalent nearly hides the mechanics while emphasizing the intent (return unless you find something).

    In Perl 5.10 we get the smartmatch, so the mechanics will be completely hidden:

    return unless $name ~~ @$stack;

    In any case, did you ever finish porting the thing to Perl? If not, can I still have the code you have so far?