Solved

Pattern Matching help

Posted on 2007-11-20
4
255 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

733 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