February 16, 2010

As I wrote in a previous blog post, I did indeed dig out my Programming Perl book over the weekend and pulled out this particular solution. I'm sure there are other Perl solutions that are much more elegant and much shorter, but give me a break, ok? It's been a while.

#! usr/bin/perl -w
$file = $ARGV[0];
$output = "new$file"; 
open (FH, "$file") or die $!;
open (FH1, ">$output") or die $!;
while(my $line = <FH>) {
    $op = lc($line);
    print FH1 $op;
}
close FH;
close FH1;

What is your Perl solution?

Edit: After Googling for a solution, I found the following on the interwebs:

perl -wpl -e 's/^.*$/\U$&/g;' filename

How's that for small?


View Comments: Comments (1) |

Comments


February 17. 2010 06:09
Phileosophos
This is why you should learn AWK. It's even better for such things than Perl. Here's the entire AWK script necessary to lower-case a file:

{ print tolower($0) }


http://phileosophos.com/http://phileosophos.com/

Add comment


(Will show your Gravatar icon)

biuquote
  • Comment
  • Preview
Loading



Recent Comments

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.