ill provide it shortly. please stay tuned.
in the meanwhile, i recommend getting comfortable with Perl's regular expression variables, and the qr// operator (very useful!). Here is an excerpt from the Perl 5.10 documentation.
VARIABLES
$_ Default variable for operators to use
$` Everything prior to matched string
$& Entire matched string
$' Everything after to matched string
$1,$2... Hold the Xth captured expr
$+ Last parenthesized pattern match
$^N Holds the most recently closed capture
$^R Holds the result of the last (?{...}) expr
@- Offsets of starts of groups.
@+ Offsets of ends of groups.
Here is an application you will need:
use strict;
use Data::Dumper;
my $con = qr/[b-df-hj-np-tv-xz]/;
my $vow = qr/[aeiouy]/;
my $ncon = qr/[^b-df-hj-np-tv-xz]/;
my $nvow = qr/[^aeiouy]/;
my $x = 'battlestar galactica';
my $y = 'silly ahab';
($x,$y) = map{swap($_)}($x,$y);
print Dumper([$x,$y]);
sub swap {
my $x = shift;
if($x =~ /(${con})(${ncon}*?\b)(${ncon}*?)(${con})/){
$x = $`.$4.$2.$3.$1.$';
} $x
}
Produces:
$VAR1 = [
'battlestag ralactica',
'silhy alab'
];
|