CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
slashes and dollar


New User

May 3, 2017, 6:20 AM

Post #1 of 2 (1282 views)
slashes and dollar Can't Post

I am learning perl using a program. I came across a piece of code,

if ($a =~ /MN_C\.o$/)

can it be stripped down to understand the meaning of backslash, forward slash and dollar


May 3, 2017, 8:34 AM

Post #2 of 2 (1277 views)
Re: [boonflies] slashes and dollar [In reply to] Can't Post

Your statement is a conditional statement that takes the 'true' branch if the string in $a ends with the substring 'MN_C.o'. Lets take it apart. The '$' tells us that the variable $a is a scalar. The operator '=~' tells us that $a must match the following regular expression. (This tells us that $a will be interpreted as string rather than as a number.) The forward slashes mark the beginning and end of the regular expression. Most characters in a regular expression represent themselves. In your example, the '\', '.', and '$' are special. The '$' requires the match to occur at the end of the string. The '\' is called an escape character. It means that the following character (the '.' in this case) loses its special meaning and merely represents itself.
Good Luck,


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives