Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Update: I just went back and checked the OP again and finally noticed that, because the OP code assigns to the hash from the output of a  map statement, the code is unquestionably changing all the keys! Consequently, this entire comment is misconceived and should be ignored. Rats. Nevermind...

Nodereaper, please bury my shame.

... requirement ... to change the hash key [to] upper case...
It is not clear to me if this means add an all-upper-case copy of any key that contains any lower case character or if it means add an all-upper-case copy of any key that contains any lower case character and delete the original key. The code of the OP certainly does the former, but, for reasons not clearly stated, that code is unacceptable.

If the latter of the two alternatives given above is needed, the following variation will do the trick. (The first hash operation is shown for demonstration purposes; only the second operation is needed for add-and-delete, i.e., change.)

>perl -wMstrict -MData::Dumper -le "my $hr = { qw(a 1 b 2 c 3 d 4) }; print Dumper $hr; $hr->{ uc() } = $hr->{$_} for keys %$hr; print Dumper $hr; $hr->{ uc() } = delete $hr->{$_} for keys %$hr; print Dumper $hr; " $VAR1 = { 'c' => '3', 'a' => '1', 'b' => '2', 'd' => '4' }; $VAR1 = { 'A' => '1', 'a' => '1', 'd' => '4', 'B' => '2', 'c' => '3', 'b' => '2', 'C' => '3', 'D' => '4' }; $VAR1 = { 'A' => '1', 'B' => '2', 'D' => '4', 'C' => '3' };

In reply to Re: changing the hash key as upper case. by AnomalousMonk
in thread changing the hash key as upper case. by santhosh_89

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found