Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6207977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:43:42+00:00 2026-05-24T05:43:42+00:00

what does Perl’s /m modifier means from this example? For example, let say I

  • 0

what does Perl’s /m modifier means from this example?

For example, let say I have the following information in the Example.txt text file. And each line ends with the newline character with a data record of Data
The input record separator is set to:

 $/="__Data__";

 Example.txt

 __Data__
 This is test A.\n
 This is test B.\n
 This is test C.\n
 This is test D.\n

Question 1, after changing the input record separator to Data, would the ^ and $ characters be position as follow?

  ^__Data__
  This is test A.\n
  This is test B.\n
  This is test C.\n
  This is test D.\n$

Question 2, let say I use the /m modifier while having the input record separator still set to Data, would the ^ and $ characters be set to the following?

  ^__Data__$
  ^This is test A.\n$
  ^This is test B.\n$
  ^This is test C.\n$
  ^This is test D.\n$

  if(/__Data__/m)
  {
      print;
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:43:43+00:00Added an answer on May 24, 2026 at 5:43 am

    /$/ is not affected by $/.

    Without /m,

    • /^/ matches the starts of the string. (/(?-m:^)/ ⇔ /\A/)
    • /$/ matches at the end of the string, and before a newline at the end of the string. (/(?-m:$)/ ⇔ /\Z/ ⇔ /(?=\n\z)|\z/)

    ^__Data__\n          "^" denotes where /(?-m:$)/ can match
    This is test A.\n    "$" denotes where /(?-m:$)/ can match
    This is test B.\n
    This is test C.\n
    This is test D.$\n$
    

    With /m,

    • /^/ matches the starts of the string and after a “\n”. (/(?m:^)/ ⇔ /\A|(?<=\n)/)
    • /$/ matches before a newline and at the end of the string. (/(?m:$)/ ⇔ /(?=\n)|\z/)

    ^__Data__$\n           "^" denotes where /(?m:^)/ can match
    ^This is test A.$\n    "$" denotes where /(?m:$)/ can match
    ^This is test B.$\n
    ^This is test C.$\n
    ^This is test D.$\n$
    

    I was asked about

    ...$\n$
    

    First, let’s demonstrate:

    >perl -E"say qq{abc\n} =~ /abc$/ ? 1 : 0"
    1
    
    >perl -E"say qq{abc\n} =~ /abc\n$/ ? 1 : 0"
    1
    

    The point is to allow /^abc$/ to match both "abc\n" and "abc".

    >perl -E"say qq{abc\n} =~ /^abc$/ ? 1 : 0"
    1
    
    >perl -E"say qq{abc} =~ /^abc$/ ? 1 : 0"
    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Perl have an enumeration type that adheres to best practices , or maybe
Does .NET have anything similar to Perl arrays, which are indexed numerically but automatically
What does the colon mean in the following Perl program? MAIN: { print Hello\n;
I have some questions about Perl's map function. Specifically: How does %hash = map
Does Perl have a build-in function to get the index of an element in
This bit of code behaves differently under Perl 5.8 than it does under Perl
Based upon SO answer my ($export = $doc) =~ s{.odt}{.pdf}; why does this Perl
Is there a single line in perl which does some magic like this. Array
Why does the first example print a wrong result ? perl -le 'print $x
The y operator in Perl does character-by-character transliteration. For example, if we do y/abc/dfg

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.