Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

uc and lc function

by Anonymous Monk
on Sep 26, 2002 at 02:46 UTC ( [id://200794]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am new to Perl, trying to use the uc and lc function and I keep getting synthax error
$name = "world"; $name = uc($name); print $name;
this gives me synthax error 2 tokens uc( Can someone be nice enough to come up with a useful hint ?

edited: Thu Sep 26 03:04:39 2002 by jeffa - code tags

Replies are listed 'Best First'.
Re: uc and lc function
by Abstraction (Friar) on Sep 26, 2002 at 02:55 UTC
    The following works for me:

    $name = "world"; $name = uc($name); print $name;


    Or you can just do a:
    $name = "world"; print uc($name);
Re: uc and lc function
by hiseldl (Priest) on Sep 26, 2002 at 02:55 UTC
    Update: Abstraction is correct. Assigning to the same var works too. Also, if you use tr you may have problems with wide characters.

    You should assign the result of uc(...) to another variable.

    $name = "world"; $uc_name = uc($name); print $uc_name,$/;

    if you want to change the case of the current variable, you could use tr.

    $name = "world"; $name =~ tr/[a-z]/[A-Z]/; print $name, $/;

    --
    hiseldl
    "Act better than you feel"

Re: uc and lc function
by Flexx (Pilgrim) on Sep 26, 2002 at 17:44 UTC

    Hi!

    The error is not in the three lines you posted. However, as the error occurs in line 9 of your script, according to the error message, there must be more than these 3 lines. I'm confident that the actual error is somewhere above line 9. It's just that the parser doesn't give up until it realizes theres no possible way to tokenize your input. And it's not until line 9 that it realizes that it's a dead end road it's travelling. ;)

    Show us the other 6 lines. I'm quite sure it's a missing semicolon, paren, brace or quote character somewhere above line 9.

    So long,
    Flexx

Re: uc and lc function
by dda (Friar) on Sep 26, 2002 at 06:52 UTC
    Could you post the exact error message here?

    --dda

      syntax error in file cc1.pl at line 9, next 2 tokens "uc(" Execution of cc1.pl aborted due to compilation errors.
        What version of perl do you use (run 'perl -v' to see it).
        Also, how do you run your code (e.g. perl cc1.pl or ./cc1.pl)?

        --dda

Log In?
Username:
Password:

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

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

    No recent polls found