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.
  • Your main question has already been answered, but you also asked why the + was there and why it wasn't \b.

    The + is actually irrelevant - it could be removed. /^\d+/ looks at the beginning of the matched text (^) for one digit (\d) or more digits (+). If the plus were changed to \b, it would require exactly one digit and disallow the line if that digit was immediately followed by an alphanumeric. If the + were removed, it would look for one digit at the start of a line (and if a line starts with one or more digits, it starts with one, so that still matches the exact same set of lines). The + would be useful in other instances, like for example, if it were just the leading numbers that were being captured instead of entire lines that start with a digit.

    /^(\d+)/ && push @list, $1 for <IN>;

    (Note that along with learning perl, you also demonstrated a need to learn html as it applies to posting here. To post the text <IN> you cannot just write it literally, since the html will decide that your IN html directive should be ignored. Instead you have to write the IO reader as &lt;IN&gt;. The preview button and a lot of experimentation are your friends...)

    • Another visual disfunction. Usually I see that written as d+ and not 'd +'. In the languages I usually program you have to be exact. Somehow I equated that with \b. No good reason why.

      I am a little puzzled by your comment on <N>. I don't recall using the term here. Was it in another journal entry? Other special characters appear in Preview as they are. But looking at it in Preview I see the angle characters vanish. Now I see. Thanks for the tip.

      • Oops, I didn't see the space in your message. That means the pattern is requiring exactly one digit, followed by one or more spaces. (The + is still pointless in this case.) If you use the x modifier on a regular expression, the space would be for formatting purposes and not matching, so /^\d+/ and /^ \d +/x are the same, but when the x is not there, spaces and other whitespace characters match themselves.

        When it is <SPACE>+, it is still not the same as \b. The \b pattern matches a "word boundary",

    • Just wrap your code examples with <ecode></ecode> and all the escaping is taken care of :)