in reply to Getting a list of all possible pattern matches

Perl has a wonderful built-in function to expand wildcards: glob. The trick is to use the {} patterns. They don't require files to exist. So we just translate your patterns to the {} versions. The range operator (..) helps us a lot, as does evaluated regexes (/e flag).
#!/usr/bin/perl use strict; use warnings; my @list = <DATA>; chomp @list; for my $pattern (@list) { # Handle the . wildcard $pattern =~ s/\./{0,1,2,3,4,5,6,7,8,9}/g; # Handle the ranges $pattern =~ s/\[([^\]]+?)\]/'{' . expand_brackets($1) . '}'/eg; # Uncomment this to see how the patterns look before being passed +to glob # print $pattern, "\n"; print "$_\n" for glob($pattern); } sub expand_brackets { my $pattern = shift; $pattern =~ s/\b(\d+)\-(\d+)\b/join ',', $1 .. $2/ge; return $pattern; } __DATA__ 1115551234 111555124. 111555125[0,3-7]

Replies are listed 'Best First'.
Re^2: Getting a list of all possible pattern matches
by inoci (Scribe) on Dec 13, 2007 at 20:48 UTC
    neato. it works, but i don't know how or why. looks like i've got some reading to do...