in reply to Formalizing an array type problem, looking for solution
#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1170935 use strict; use warnings; sub flip { join '', reverse map tr/-+/+-/r, /\w./g } my $all = ' ' . join ' ', map { "$_," . flip() . ' ' } map tr/ :\n//dr +, <DATA>; my %firsts; @firsts{ $all =~ /[, ](\w[+-])/g } = (); my @queue = map "$_ $all", sort keys %firsts; while( $_ = shift @queue ) { if( /^(\S+)\s*$/ ) { print join ' : ', $1 =~ /\w./g; } else { /^(\S*)(\w.)( .*? )\2([\w+-]*),[\w+-]*( .*)$(?{ push @queue, "$1$2$4$3$5" })(*FAIL)/; /^(\S*)(\w.)( .*? )[\w+-]*,\2([\w+-]*)( .*)$(?{ push @queue, "$1$2$4$3$5" })(*FAIL)/; } } __DATA__ A+ : B+ C+ : D- : E- E- : B-
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Formalizing an array type problem, looking for solution
by GrandFather (Saint) on Sep 02, 2016 at 01:41 UTC | |
by Anonymous Monk on Sep 02, 2016 at 21:08 UTC | |
by GrandFather (Saint) on Sep 04, 2016 at 21:08 UTC |