Solved

Pattern Matching help

Posted on 2007-11-20
4
262 Views
Last Modified: 2010-04-21
Please explain following line of perl code in detail.  Earlier in code TEMP handle has debugging information.  A line at a time is assigned to line macro from TEMP handle until TEMP handle reaches EOF.


if ($line =~ m/.+:\s+TAG\_compile\_unit/)
{
   ...
}
0
Comment
Question by:naseeam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 20323689
This is checking to see if the variable $line matches a pattern, and if so, do something.

The pattern:
m/                                  Starts of pattern.  When using / as the delimiter, the m is optional
.+                                   Any character except \n, 1 or more times
:                                    The colon character
\s+                                Whitespace (space, tab), 1 or more times
TAG\_compile\_unit       the string "TAG_compile_unit".  The \ are not necessary here
/                                    End of the pattern
0
 
LVL 1

Author Comment

by:naseeam
ID: 20323760
What is =~ in the above if condition?

Thanks.
0
 
LVL 1

Author Closing Comment

by:naseeam
ID: 31410235
Quick Response.  Accurate detailed answer.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 20323992
That is used to do match the thing on the left ($line in your case) with the pattern on the right.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question