Sergy Stouk
asked on
lowerCase to Uppercase
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.
I guess it should be in some of the books but I think I missed it somehow.
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;
$var =~ s/^(\w+)/\U$1/g;
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?
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?
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
open (readingfile)
open (writingfile)
read one line of readingfile in $line
$line =~ tr/^[A..Z]/[a..z]/
print $line in writingfile
- Thanks
ASKER
Adjusted points to 75
ASKER
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_Som e_Lower_Ca se.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.
Example:
Input:
"this Is the _line with_Some lower Case.rar"
Output:
"This_Is_The_Line_With_Som
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect Answer!
Thank You very much!
Thank You very much!
ASKER
I tested it and it works OK as this:
$string=~s/([A-Z]+)/ucfirs t($1)/egi;
and as this:
$string=~s/([a-z]+)/ucfirs t($1)/eg;
$string=~s/([A-Z]+)/ucfirs
and as this:
$string=~s/([a-z]+)/ucfirs
errr - thanks, and you second solution is the "perfect" answer. What did I think when i posted mine?
Too early in the morning :-)
Tobias
Too early in the morning :-)
Tobias
#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;
#(you also don't need the /e)
$string=~s/([a-z.]+)/\u$1/
ASKER
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.
:)
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.
:)
$var =~ s/^(.)/\u$1/;