Last active
September 30, 2021 16:44
-
-
Save stelf/6fa57a87274c7834c9d999ef3ca1288d to your computer and use it in GitHub Desktop.
dynamic regex switch (Perl5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use feature say; | |
my @a = ( | |
" asd", | |
" asd ", | |
" bsd", | |
" XXX", | |
"10000" | |
); | |
my $spacer; | |
foreach(@a) { | |
/^\s+/ and length($spacer) < length($&) and ( $spacer = $& ); | |
/^${spacer}/ | |
and say("Spacer with length ".length($spacer)." is present in [$_]") | |
or say("Spacer with length ".length($spacer)." is not present in [$_]"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment