Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1108680]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2023-12-06 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (31 votes). Check out past polls.

    Notices?