Solved

lowerCase to Uppercase

Posted on 2000-02-15
12
140 Views
Last Modified: 2010-03-05
How to use the s/// operator and substitute the words in the line beginning with lowercase to uppercase.
I guess it should be in some of the books but I think I missed it somehow.
0
Comment
Question by:sstouk
  • 5
  • 2
  • 2
  • +2
12 Comments
 
LVL 4

Expert Comment

by:dda
ID: 2525645
Possible solution, may be not the better one:

$var =~ s/^(.)/\u$1/;
0
 
LVL 4

Expert Comment

by:dda
ID: 2525660
sstouk, please ignore my previous comment, it will replace only the first char of the line. More likely you want the following:

$var =~ s/^(\w+)/\U$1/g;

0
 
LVL 84

Expert Comment

by:ozo
ID: 2526004
I'm not sure I understand what you mean.  
Do you want to substutute only the beginning letter of each word?
or do you want to substitute the entire word depending on the case of its beginning letter?
0
 
LVL 5

Expert Comment

by:amitpagarwal
ID: 2526500
you need to read one file and write it to another file. Both things can't be done at the same time.

open (readingfile)
open (writingfile)

read one line of readingfile in $line

$line =~ tr/^[A..Z]/[a..z]/

print $line in writingfile

- Thanks

0
 
LVL 6

Author Comment

by:sstouk
ID: 2527118
Adjusted points to 75
0
 
LVL 6

Author Comment

by:sstouk
ID: 2527119
I need not the tr/// operator to do it, but the s/// operator as stated in the question.

Example:
Input:
"this Is the _line with_Some lower Case.rar"
Output:
"This_Is_The_Line_With_Some_Lower_Case.rar"

That's what I try to archieve.
I have a script that can substitute the spaces in the filename to the underscores and substitute the unaccepted charachters, but I need also to make the beginning of each word in the filename as Uppercase.

I tested dda's coment and it only replaces the first word completely to uppercase.

I don't need the tr/// operator as there are some "(,),-,_ in the beginning of words and I need only forst letters of each word to be uppercase.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Accepted Solution

by:
thoellri earned 70 total points
ID: 2527434
You could use this:

$string="this Is the _line with_Some lower Case.rar";
$string=~s/(\w+)/ucfirst($1)/eg;
print $string,"\n";

however "_" is considered a word character and I think you only want alpha-characters, so use:

$string=~s/([A-Z]+)/ucfirst($1)/egi;


hope this helps
  Tobias
0
 
LVL 6

Author Comment

by:sstouk
ID: 2527489
Perfect Answer!

Thank You very much!
0
 
LVL 6

Author Comment

by:sstouk
ID: 2527521
I tested it and it works OK as this:
$string=~s/([A-Z]+)/ucfirst($1)/egi;


and as this:
$string=~s/([a-z]+)/ucfirst($1)/eg;


0
 
LVL 5

Expert Comment

by:thoellri
ID: 2527527
errr - thanks, and you second solution is the "perfect" answer. What did I think when i posted mine?

Too early in the morning :-)
  Tobias
0
 
LVL 84

Expert Comment

by:ozo
ID: 2528760
#That would capitalise the .Rar, which sstouk's example did not want.
#(you also don't need the /e)
$string=~s/([a-z.]+)/\u$1/gi;

0
 
LVL 6

Author Comment

by:sstouk
ID: 2528918
I admit the ozo's answer worked from the first time as I don't have to make several s/// operator lines for files with the Absolute Path.
The first suggestion would do OK though and as a compensation for a better option here's the link
http://24.112.136.42
With the result of your suggestions in work.
please don't break my computer. I have just started studying Perl.
 :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl for loop for 2000 ms 7 97
transpose into pipe delemited 8 67
Executing multiple sybase statements in perl dbi 2 88
quoting a comma separated list 20 82
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now