Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: Regular expressions across multiple lines

by Discipulus (Canon)
on Apr 24, 2016 at 19:00 UTC ( [id://1161387]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Regular expressions across multiple lines
in thread Regular expressions across multiple lines

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1161387]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-03-28 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found