aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-09-12 22:01:18 -0400
committerTeddy Wing2016-09-12 22:01:18 -0400
commit93c786a91c6b388be1a69b9cd8ea22d807a79fe5 (patch)
treed80e792257d6c9fe3b03192d3c06197ee51321b3
parent632756c840db15dfc64aa3a3e7c19d0b68bacca1 (diff)
downloadirssi-slack-profile-93c786a91c6b388be1a69b9cd8ea22d807a79fe5.tar.bz2
Add `underscorize` subroutine
Takes a string and returns a lowercased underscored representation of it with non-alphabetic characters removed. Examples: GitHub string's Karma This is a test BOOYA KACHA Test @%^Test Becomes: github_strings karma this_is_a_test booya_kacha test_test
-rw-r--r--slack_profile.pl10
1 files changed, 10 insertions, 0 deletions
diff --git a/slack_profile.pl b/slack_profile.pl
index d4ddae2..6cd4cbe 100644
--- a/slack_profile.pl
+++ b/slack_profile.pl
@@ -156,6 +156,16 @@ sub fetch_user_presence {
return $resp->{'presence'};
}
+sub underscorize {
+ my ($string) = @_;
+
+ my $result = lc $string;
+ $result =~ s/ /_/g;
+ $result =~ s/[^a-z_]//g;
+
+ return $result;
+}
+
sub update_user_profile {
my ($key, $value) = @_;