The syntax

$line =~ //

is short hand for

$line =~ m//

and checks if the contents of variable $line match the pattern surrounded by the //. Details on regular expressions can be found in the documentation in Perl regular expressions, quick reference guide, and tutorial. The pattern to be matched is

^([^{};]+[{};])(\s*\S+.*)$

and uses the s modifier, which tells the regex engine to treat the whole string as 1 line. The pattern does the following, in order:

  1. ^Start at the start of the string
  2. [^{};]+Match at least 1 of the characters other than {,} and ; (^ is not)
  3. [{};]Match exactly 1 of the characters {,} and ;
  4. \s*Match any amount of whites space (including none)
  5. \S+Match at least one non-white space character
  6. .*Match any number of any character
  7. $Stop at the end of the string

([^{};]+[{};]) also stores the punctuation in the variable $1 and (\s*\S+.*) stores the rest of the string in $2. If the string matches, then the conditional is true and the if block is executed.

Update: Cleaned up the above and put it in list form.

Update 2: I'm an idiot. When inside [], a carat means not. Thanks, cdarke.


In reply to Re: Help with Perl RE by kennethk
in thread Help with Perl RE by newbie2009

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.