Changing text case utility


/ Published in: Perl
Save to your folder(s)

Just run in your consol window as ./tocase (or whatever you call the file). Be sure to give it proper permission first (chmod 755 tocase) :]


Copy this code and paste it in your HTML
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use 5.010;
  4.  
  5. my ($type, $string);
  6.  
  7. print "What type of case? (upper/lower):\n";
  8. while (<STDIN>) {
  9. if (/^(upper|lower)$/i) {
  10. $type = $_;
  11. last;
  12. } else {
  13. print "Invalid type please type upper or lower:\n";
  14. }
  15. }
  16.  
  17. print "Please enter your text:\n";
  18. chomp($string = <STDIN>);
  19. given ($type) {
  20. when ("upper") { print "\U$string" }
  21. when ("lower") { print "\L$string" }
  22. }
  23.  
  24. print "\n";

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.