First of all, is that assignment to $evalme on purpose? Are you in fact evaling the variable after this?

Second, you don't need the s/^ //; line. What it does is remove a single space from the beginning of the line. But if you want to ignore one leading space, you may as well ignore any leading whitespace:

if (/^\s*HISTOGRAM ...rest of re.../)

In fact, it may (or may not, depending on how well-formed your data is) be reasonable to just drop the ^ anchor.

Finally, for the reason why this regexp fails. You have "OF(\w+)$", which reads "the word characters that continuously occupy from immediately after the letters "OF" to the end of the line". This must fail because you have non-word characters in the rest of your line, indeed you have a space *immediately* after "OF"!

I couldn't understand if you're looking for the word that comes between the next two asterixes ("gpa" in this example) or if the next text inside parentheses (" 226" in this example) is what you want to capture. If the former, the following should work. I'm using extended regexp syntax for added readability:

m{ HISTOGRAM \s+ OF \s+ \* \s* # a literal "*", escaped because * is a metacharacter ([^*]+?) # (capture) anything that isn't a "*", nongreedy \s* \* }x;

The group "(^*+?)" is "nongreedy", which means that (since it is followed by \s*, whitespace) it will automatically not include any trailing whitespace between the word and the following asterix.


In reply to Re: regular expressions. help by gaal
in thread regular expressions. help by apocalyptica

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.