The code:
#!/usr/bin/perl
my $string="string\nstring2\nstring3";
print "$string\n-----\n";
$string=~s/^.*$/_/;
print "$string\n-----\n";
The Output:
string
string2
string3
-----
string
string2
string3
-----
Expected Outputs:
1:
string
string2
string3
-----
_
-----
2:
string
string2
string3
-----
_
string2
string3
-----
3: (like /m modifer):
string
string2
string3
-----
_
_
_
-----
The question: Why without /m ^..$ broke things ? What i missed in regex docs ?
/scauses.to match newlines./mcauses^and$to match start and end of line rather than start and end of input./gcauses all matches to be replaced.So,
s/^.*$/_/s;s/^.*$/_/m;s/^.*$/_/mg;