$x = 'andrew john';
# swap the first and second word around
$x=~ s/ (\w+) \s+ (\w+*)
/ $2 $1
/ x;
# s/ - substitute
# (\w+) - 1+ word charcters, captures as $1
# \s+ - 1+ whitespace characters
# (\w+) - 1+ word chars, captured as $2
# /x - use whitesapce and comments
# $1 and $2 survive
print $2;
# prints john
No comments:
Post a Comment