Skip to content

Instantly share code, notes, and snippets.

@stelf
Last active September 30, 2021 16:44
Show Gist options
  • Save stelf/6fa57a87274c7834c9d999ef3ca1288d to your computer and use it in GitHub Desktop.
Save stelf/6fa57a87274c7834c9d999ef3ca1288d to your computer and use it in GitHub Desktop.
dynamic regex switch (Perl5)
#!/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