To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.off-topic.geekOpen lugnet.off-topic.geek in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Off-Topic / Geek / 573
572  |  574
Subject: 
Re: Perl question
Newsgroups: 
lugnet.off-topic.geek
Date: 
Mon, 4 Oct 1999 22:50:15 GMT
Reply-To: 
JSPROAT@IO.COMavoidspam
Viewed: 
236 times
  
David Eaton wrote:
Any nice easy way to make a string all lower case? ("nice easy way" being
defined as being less than 5 lines...)I seem to remember being able to use
'pack' to do that in some fashion or another... and of course I foolishly
tried: "$string =~ s/[A-Z]/[a-z]/g;" but of course that was just a desperate
hope that it might be easy... any suggestions?

Try this:

$string = lc $string;

Alternatively, I think this will work also:

$string =~ tr/[A-Z]/[a-z]/;

But if you *REALLY* want to make it look impressive (to a 1st-year programmer
anyway :-), you could do:

@upchars = qw( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z );
@lowchars = qw( a b c d e f g h i j k l m n o p q r s t u v w x y z );
for( $c = 0; $c < scalar @upchars; $c++ ) {
  $uptolow{$upchars[$c]} = $lowchars[$c];
}

#...more code...

$string = join( "", map( { $uptolow{$_} || $_ } split( //, $string ) ) );

Dang, but I *LOVE* TMTOWTDI!  :-P

Cheers,
- jsproat

--
Jeremy H. Sproat <jsproat@io.com> ~~~ http://www.io.com/~jsproat/
"I've spent the past few years building up an immunity to bullets."
- Angus McGuire



Message has 1 Reply:
  Re: Perl question
 
(...) Doh! I had no idea there was a function to do it already! DaveE (25 years ago, 5-Oct-99, to lugnet.off-topic.geek)

Message is in Reply To:
  Perl question
 
Any nice easy way to make a string all lower case? ("nice easy way" being defined as being less than 5 lines...)I seem to remember being able to use 'pack' to do that in some fashion or another... and of course I foolishly tried: "$string =~ (...) (25 years ago, 4-Oct-99, to lugnet.off-topic.geek)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR