Posted By

davidmoreen on 08/09/10


Tagged

text case utility


Versions (?)

Changing text case utility


 / Published in: Perl
 

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) :]

  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
Posted By: davidmoreen on August 9, 2010

Example: $~ chmod 755 tocase $~ ./tocase What type of case? (upper/lower): upper Please enter your text: hello world HELLO WORLD $~

You need to login to post a comment.