I can usually figure out regexes, and this one seems simple, but it still eludes me--
I'm looking for a regex (or a couple of regexes) to do the following:
blahblah{ab,abcd}blah --> blahblah(ab|abcd)blah blahblah{a,b,c}blah --> blahblah(a|b|c)blah
If it's not obvious I'm trying to glob-select files like the tcsh would. I've got the rest, this is the last part...
$var =~ s<{([^}]+)}><(?:@{[ ($a = $1) =~ y/,/|/; $a ]})>;
Luke's suggestion blew me away, but I finally came to deal with it. Now this one blew me away again...
John, can you explain what this does?
(?:@{[ stuff ]})
The string above would be somewhat equivalent to:
join '', '(?:', stuff, ')';
"stuff" is inside of [] which is perl's method of creating an anonymous array, which is inside of @{} which is perl's method of dereferencing an array reference. As you may know, the second part of the substitution operator is the same as a double quoted string (see perlop for details on both) and any variable that starts with a $ or @ character is interpolated but may be evaluated as well.
$ perl -le' sub test { my @x = 3 .. 7; return wantarray ? @x : 2 } my @x = 91 .. 99; my $x = q!98765!;
print "[EMAIL PROTECTED] 5 [EMAIL PROTECTED] 3, 5, 7 ]---"; # normal interpolation print "---$x[ test [EMAIL PROTECTED] test ]---"; # expression evaluation print "---${\( test )[EMAIL PROTECTED] test ]}---"; # expression evaluation print "---${\( scalar test )[EMAIL PROTECTED] scalar test ]}---"; # expression evaluation ' ---98765---91 92 93 94 95 96 97 98 99---96---94 96 98--- ---93---94 95 96 97 98--- ---7---3 4 5 6 7--- ---2---2---
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>