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:
- ^Start at the start of the string
- [^{};]+Match at least 1 of the characters other than {,} and ; (^ is not)
- [{};]Match exactly 1 of the characters {,} and ;
- \s*Match any amount of whites space (including none)
- \S+Match at least one non-white space character
- .*Match any number of any character
- $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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.