Skip to content

Instantly share code, notes, and snippets.

@cowens
Created July 7, 2009 14:31
Show Gist options
  • Save cowens/142109 to your computer and use it in GitHub Desktop.
Save cowens/142109 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
my $s = "";
for my $s (qw/ ab ba /) {
my @match = $s =~ /(a)(b)|(b)(a)/;
my ($a_match, $b_match) = @match;
unless (defined $a_match) {
($b_match, $a_match) = @match[2,3];
}
print "given $s\n\told match: a is $a_match and b is $b_match\n";
$s =~ /(?<a>a)(?<b>b)|(?<b>b)(?<a>a)/;
print "\tnew match: a is $+{a} and b is $+{b}\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment