Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Pattern Matching help

Posted on 2007-11-20
4
Medium Priority
?
267 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
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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
Suggested Courses

580 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