Search code examples
perlrangeglob

Perl glob range permutations


Need to use Perl in order to create permutations

Need to know if glob allows me to create different permutations based on ranges: numeric or strings [1..9] or ['a'-'z']

Examples: perl -le 'print for glob "{L,E,V}{1,2,3,4,5}"' I want to not manually enter 1,2...5. Possibilites from 1 to 100 for values L E V

  1. L
  2. L
  3. L
  4. L
  5. L

thanks


Solution

  • No, glob does not do that, unless files with all those names exist. Only explicitly listed filename parts are returned by glob whether or not the file exists.

    But you can use perl to build up the list for you:

    @list = glob '{L,E,V}{' . join(',', 1..100) . '}';
    

    However, since the only real reason to use glob for this is how easy and terse it is, at this point it makes sense to look for non-glob solution.

    Here's one:

    @list = map {
        my $lev = $_;
        map $lev . $_, 1..100;
    } qw/L E V/;