I have a list of characters. I need to get a list of all possble sequences of these characters for example.
I have a string that consists of '-mevqgn' I need to pattern match any combination of 'mevqgn' with a preceding - or --.
Right now this is what I am doing but it is very ugly and difficult to come up with the combinations and it makes my brain hurt!:
if ($LS_Val =~ /-{1,2}(mevqgn|
emvqgn|evmqgn|evqmgn|evqgmn|evqgnm|
veqgnm|vqegnm|vqgenm|vqgnem|vagnme|
qvgnme|qgvnme|qgnvme|qgnmve|qgnmev|
gqmnev|gmqnev|gmnqev|gmneqv|gmnevq|
mgnevq|mngevq|mnegvq|mnevgq|mnevqg|
nmevqg|nemvqg|nevmqg|nevqmg|nevqgm|
envqgm|evnqgm|evqngm|evqgnm|evqgmn|
)/i)
{
#Do Something;
}
A subroutine that takes the string of characters as an argument and then returns 1 on success and undef on fail would be ideal for my purpose.
if ($val =~ /^--?[mevqgn]{6}$/) almost works, but allows, e.g. -megggg, i.e. repetitions.
I would just do:
if (($val =~ /^--?([a-z]+)$/) && (length($1)==6) && check($1, qw(m e v q g n))) {
sub check { my($str, @chars) = @_;
Full test program: -------------------------------------
use strict;
MAIN: {
test('');
test('-');
test('--');
test('-mev');
test('-mevqgn');
test('--mevqgn');
test('--qvgnme');
test('-qgvnme');
test('--qgnvme');
test('--qgnmve');
test('-qgnmev');
}
# ------------------------------------------
sub test { my($str) = @_;
if (($str =~ /^--?([a-z]+)$/)
else {
} # test
# ------------------------------------------
sub check { my($str, @chars) = @_;
foreach my $ch (@chars) {
return 1;
} # check
John Deighan
Public Consulting Group
1700 Kraft Dr.
Suite 2250
Blacksburg, VA 24060
[EMAIL PROTECTED]
540-953-2330 x12
FAX: 540-953-2335