Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Changing the first word to uppercase

by ikegami (Patriarch)
on Feb 14, 2008 at 00:28 UTC ( [id://667852]=note: print w/replies, xml ) Need Help??


in reply to Changing the first word to uppercase

perl -pe"s/(.)/uc($1)/e" infile > outfile
or
while (<>) { s/(.)/uc($1)/e; print; }

Update: Oops, switch lc with uc.

Replies are listed 'Best First'.
Re^2: Changing the first word to uppercase
by bmann (Priest) on Feb 14, 2008 at 01:18 UTC
    What's the reason you chose s/.../uc($1)/e over s/.../\U$1/?
      I only thought of \U afterwards. I'm not a big fan of it either. Code shouldn't look like a string literal. And unlike interpolation, it's not something we are trained to look for.
Re^2: Changing the first word to uppercase
by Anonymous Monk on Feb 14, 2008 at 00:35 UTC
    tx for ur help but it didnt work, it gave me the same line wid space after each line, it means my "word w o r d" now is "word w o r d word w o r d".....

      I accidentally used lc where I should have used uc, but you shouldn't get the behaviour you describe either way.

      >type infile hello h e l l o bye b y e bike b i k e >perl -pe"s/(.)/uc($1)/e" infile > outfile >type outfile Hello h e l l o Bye b y e Bike b i k e

      or

      >type infile hello h e l l o bye b y e bike b i k e >type script.pl while (<>) { s/(.)/uc($1)/e; print; } >perl script.pl infile > outfile >type outfile Hello h e l l o Bye b y e Bike b i k e

      You must be doing something extra.

        Sorry for disturbing again. for mu input such as below i get this out put:
        abandoned ax bcl b ae n dcl d en dcl d abdomen ae bcl b dcl d ow m en abdomen ae bcl b dcl d em en abdomen ae bcl b dcl d ax m ax n ABANDONED AX BCL B AE N DCL D EN DCL D bandoned ax bcl b ae n dcl d en dcl d ABDOMEN AE BCL B DCL D OW M EN bdomen ae bcl b dcl d ow m en ABDOMEN AE BCL B DCL D EM EN bdomen ae bcl b dcl d em en ABDOMEN AE BCL B DCL D AX M AX N
        which is not desired:(
Re^2: Changing the first word to uppercase
by Anonymous Monk on Feb 14, 2008 at 01:37 UTC
    Dear Friend I still couldnt solve it:) it gives me an unexpected output:(

      We can't help solve "it doesn't work". Show us this code, the input you use, the output you get and the output you want.

      Update: I see you posted the input and output already, but not the code you used.

Log In?
Username:
Password:

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

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

    No recent polls found