On Sun, 05 Oct 2008 19:06:35 -0400, Mr. Shawn H. Corey wrote:
> On Sun, 2008-10-05 at 15:11 -0700, Randal L. Schwartz wrote:
>> my @result = map [split /-/], glob "{a}-{b,c}-{d,e,f}-{a}";
>> 
>> :-)
>> 
>> But seriously, why does this come up often?
> 
> Because your solution relies on knowledge of bash which many Windows
> users do not have.

Not bash, but File::Glob, which Windows users of Perl do have.

Did you see the smiley?  Randal might have been more inclined to give a
less cute answer if the poster said what he wanted this for, because it
does sound like homework.  But anyway, here's my less cute answer:

use Data::Dumper;

print Dumper combine( ['a'], [qw(b c)], [qw(d e f)], ['a'] );

sub combine {
  my $x = shift or return [];
  return map { my $y = $_; map { [ $y, @$_ ] } combine( @_ )
             } @$x;
}

> Also this ability of glob is not documented in perldoc.

Yes it is.  perldoc -f glob says:

               Beginning with v5.6.0, this operator is implemented using the
               standard "File::Glob" extension.  See File::Glob for details.

Following the reference to File::Glob we find:

       The metanotation "a{b,c,d}e" is a shorthand for "abe ace ade".  

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to