#!/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-
In reply to Re: Formalizing an array type problem, looking for solution
by Anonymous Monk
in thread Formalizing an array type problem, looking for solution
by melmoth
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |