in reply to Re^2: /m pattern matching modifier
in thread /m pattern matching modifier
For 'g' to work in scalar context you need to search multiple times. AND you have to search the same variable, because the variable remembers the location up to which it searched last. Or use an array and list context:
Scalar usage:
#scalar usage: my $x="AAC\nGTT"; my $i=0; while ($x=~/^.*$/mg) { print $&; } #or do the loop by foot if you know how many times it will match: my $x="AAC\nGTT"; $x=~/^.*$/mg; print $&; $x=~/^.*$/mg; print $&;
or use the regex in list context:
my $x="AAC\nGTT"; my @allhits= $x=~/^.*$/mg; print join(" - ", @allhits),"\n";
|
|---|