more useful options | |
PerlMonks |
Re^3: Regular expressions across multiple linesby Discipulus (Canon) |
on Apr 24, 2016 at 19:00 UTC ( [id://1161387]=note: print w/replies, xml ) | Need Help?? |
you welcome, even if i'm not sure to understand your issue. Basicly a\n?b\n?c means match a followed by, perahps ? a newline \n followed by a b followed by, perahps ? a newline \n and a c The m regex modifier (probably unneeded in my example) stands for multiline and the g one means globally ie all occurences are returned. $count=()=$string=~/pattern/g idiom is used to count the occurences of pattern in $string infact $string=~/pattern/g with the g returns a list and the generic list () is provided and it's scalar value (ie the number of elements) is returned to the scalar $count For shortness i put your example data into a doublequoted string using qq operator qq(abcdefab\ncdefa\nbcdef) the rest is only print stuffs. If you want to slurp a file into a string you can play with $/ aka input record separator, see perlvar and How do I read an entire file into a string? L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
In Section
Seekers of Perl Wisdom
|
|