I didn't realize until today that the unifying idea behind regular expressions and XPath and all the other nifty pattern matching stuff available in neato-keen languages like Oz, Erlang, Haskell, Prolog, etc is that "regexps" and XPath were just convenient syntaxes to generate input to unification operations.
Consider the expression
'abc' =~ /^[a-z]+\z/
[ 'a' 'b' 'c' ]and conceptually, the regexp is a stream of
any( 'a' .. 'z' )values which unify to any of the values a through z.
%foo = (
a => 1,
b => 2,
c => 3,
d => 4,
);
# Now apply yon unification operator
\ %foo ~~ {
$bar => 1,
$baz => 2,
c => $c,
};
# The following variables would then be populated.
assert( $bar eq 'a' )
assert( $baz eq 'b' )
assert( $c eq '3' )