Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: uppercase/lowercase in a single expression

by chargrill (Parson)
on Sep 07, 2006 at 17:07 UTC ( [id://571747]=note: print w/replies, xml ) Need Help??


in reply to uppercase/lowercase in a single expression

In the spirit of TIMTOWTDI, here's a pointless regex version. But if this indeed IS homework, turning this in will certainly impress your teacher.

#!/usr/bin/perl use strict; use warnings; my $line1 = 'asdadAADSAsdfsfASASDjljsdASDAS'; my $line2 = 'GKHSKJADHasdadhkadhGHKJHKJHasdada'; for my $word( $line1, $line2 ){ print "Before: $word\n After: "; $word =~ /((\w)\W*(?{ ord $2 > 96 })(?{ print $^R ? uc $2 : lc $2 }) +)+/; print "\n\n"; }

Output:

Before: asdadAADSAsdfsfASASDjljsdASDAS After: ASDADaadsaSDFSFasasdJLJSDasdas Before: GKHSKJADHasdadhkadhGHKJHKJHasdada After: gkhskjadhASDADHKADHghkjhkjhASDADA


--chargrill
$,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://571747]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found