Pattern matching in perl
The eduladder is a community of students, teachers and programmers just interested to make you to pass any exams. So we solve question papers for you.
See Our team
Wondering how we keep quality?
Got question?

Ask Questions

Use Me  ?

New searches
You are here:-->View note-->View question

Write a note on pattern matching on perl programming language with an example.

These examples use very simple regexps only. The intent is just to show contexts where regexps might be used, as well as the effect of some “flags” to matching and replacements. Note in particular that matching is by default case-sensitive (Abc does not match abc unless specified otherwise).

s/foo/bar/;
replaces the first occurrence of the exact character sequence foo in the “current string” (in special variable $_) by the character sequence bar; for example, foolish bigfoot would become barlish bigfoot

s/foo/bar/g;
replaces any occurrence of the exact character sequence foo in the “current string” by the character sequence bar; for example, foolish bigfoot would become barlish bigbart

s/foo/bar/gi;
replaces any occurrence of foo case-insensitively in the “current string” by the character sequence bar (e.g. Foo and FOO get replaced by bar too)

if(m/foo/)...
tests whether the current string contains the string foo




By:electron

Taged users:
|metaphor|Rajiv|arunwebber|neenu2|edu-Freak|scribed

Likes:
Be first to like this question

Dislikes:
Be first to dislike this question
Talk about thisDelete|Like|Dislike|


Answers

These examples use very simple regexps only. The intent is just to show contexts where regexps might be used, as well as the effect of some “flags” to matching and replacements. Note in particular that matching is by default case-sensitive (Abc does not match abc unless specified otherwise).

s/foo/bar/;
replaces the first occurrence of the exact character sequence foo in the “current string” (in special variable $_) by the character sequence bar; for example, foolish bigfoot would become barlish bigfoot

s/foo/bar/g;
replaces any occurrence of the exact character sequence foo in the “current string” by the character sequence bar; for example, foolish bigfoot would become barlish bigbart

s/foo/bar/gi;
replaces any occurrence of foo case-insensitively in the “current string” by the character sequence bar (e.g. Foo and FOO get replaced by bar too)

if(m/foo/)...
tests whether the current string contains the string foo


Amogh

Likes:
Be first to like this answer

Dislikes:
Be first to dislike this answer
Talk about thisOnce you have earned teacher badge you can edit this questionDelete|Like|Dislike|
------------------------------------

You dont have permission to add an answer herePlease see this

Join us to pass any exams easily