Pattern Matching help

Posted on 2007-11-20
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/)
Question by:naseeam
  • 2
  • 2
LVL 39

Accepted Solution

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

Author Comment

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


Author Closing Comment

ID: 31410235
Quick Response.  Accurate detailed answer.
LVL 39

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connecting to linux server using Net::Telnet module 25 220
PERL get the value for query 4 145
Excel to CSV conversion with specific columns 5 74
Export Variables in Perl 3 46
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now