Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Two-dimensional match/regex? (2)

by Loops (Curate)
on Nov 28, 2014 at 23:56 UTC ( #1108680=note: print w/replies, xml ) Need Help??


in reply to Two-dimensional match/regex? (2)

Howdy,

It's easier if you just search by column:

my $data = do { local $/; <DATA> }; my $p1 = qr(.{1}#); my $p2 = qr(#); my $p3 = qr(.{2}#\.); for my $column (0 .. 80) { my $start = qr(.{$column}); my $next = qr(.*\n$start); my $target = qr($start(?=$p1$next$p2$next$p3)); while ( $data =~ m/^$target/mg) { my $row = () = substr($data,0,pos $data) =~ /\n/g; print "[row: $row|column: $column]\n"; } } __DATA__ #..#.....#. ..#...##... .#....#..## #..#....#.. ..#...#..#. .......#.#. ...........
Prints:
[row: 2|column: 0] [row: 1|column: 1] [row: 1|column: 6]

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2021-04-15 01:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?