First and foremost: do not undef $/ unless this is a script that...

  1. is a throwaway script.
  2. doesn't use any other modules that just might happen to open a file for reading.
  3. you don't and never will work with a developer who is an avid gun collector and also has a low tolerance for weird stuff in scripts he has to maintain.

If none of those apply to the script in question, go ahead. Of course, otherwise you probably want to use as small of a scope as possible and localize $/. Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> }; by jeffa might help out with a preferred way to do it.

In regards to your regex question, you're merely checking whether or not $Hap contains INT8U followed somewhere later by a right parenthesis. You then happily print $Hap. Of course, I'm curious about a few things. You want to capture the void what(void *kiss,INT8U\nmiss) but it's somewhat difficult to know how to design our regex unless we know a few things: Will the lines always come in pairs? Will the first line always start with void or is there a list of keywords that can be there or can it be just anything? If INT8U isn't on the same lines as the opening parenthesis, should we still match the entire line? Is it legal to have our opening left parenthesis at the beginning of a new line? Can parentheses be somehow embedded within the parentheses? Will we always be looking for INT8U or does it depend upon a variable? Should we stop capturing at the closing right parenthesis or should we capture that entire line?

Those are the questions you need to recognize and ask yourself prior to attempting to write your regular expression. Once you can do that, recognizing text patterns and deciding upon a regex to describe those patterns becomes much easier, even natural. In short, check out perldoc perlretut for a basic introduction to regular expressions as well as the difference between matching and substituting as well as when and when not to capture. Whenever you think you have a good grip on the basics, read perldoc perlre for everything you'd ever want to know about regular expressions.

While I somewhat doubt I've helped you with your problem, I hope this at least helps you to become more proficient with regular expressions.


In reply to Re: Trouble matching more than one line by !1
in thread Trouble matching more than one line by Levan

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.