in reply to using bits to print part of a string
Hi all,
I like choroba's solution. Therefor a ++. I just want to show my solution to prove the TMTOWTDI of perl. ;-)
my @strings = ( 'Abcderd', 'dkdnnjn', 'ddjfdjk', 'c,oktnx', ); my $mask = '0100110'; my $regex = '^' . join('', map { $_ ? '(.)' : '.' } split //, $mask) . + '$'; foreach my $string (@strings) { my $result = join '', ($string =~ m/$regex/o); print $result, "\n"; }
Best regards
McA
|
|---|