Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Hashes... Light switch isn't coming on

by muba (Priest)
on Dec 12, 2012 at 18:11 UTC ( #1008548=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # Snippet 1 - a stepping stone
    use strict;
    ...
    
    # Heck, Alice, Bob, Charlie -- they're all pretty cool!
    print Dumper \%phonebook;
    
  2. or download this
    Bob's digits are 555 9876
    
    ...
              'Alice' => '555 1234',
              'Charlie' => '555 2580'
            };
    
  3. or download this
    # Snippet 2a - another stepping stone
    use strict;
    ...
    
    # Gimme all their digits!
    print Dumper \%phonebook;
    
  4. or download this
    Alice's home number is 555 1234
    Charlie's mobile number is 555 2468
    ...
                             'home' => '555 3456'
                           }
            };
    
  5. or download this
    # Snippet 2b - append to snippet 2a
    for (1..3) {
        printf "Alice and Bob: %s and %s\n", \%alice, {%bob}
    }
    
  6. or download this
    Alice and Bob: HASH(0x328358) and HASH(0x380138)
    Alice and Bob: HASH(0x328358) and HASH(0x3801e0)
    Alice and Bob: HASH(0x328358) and HASH(0x380168)
    
  7. or download this
    # Snippet 2c -- append after 2b
    delete $alice{home};            # Delete Alice's home number **from he
    +r original hash**
    ...
    delete $phonebook{Charlie};     # Let's not clutter the output
    
    print Dumper \%phonebook;
    
  8. or download this
    $VAR1 = {
              'Bob' => {
    ...
                           'mobile' => '555 2580'
                         }
            };
    
  9. or download this
    # Snippet 3 - your answer?
    use strict;
    ...
        }
    }
    print Dumper \%phonebook;
    
  10. or download this
    $VAR1 = {
              'bar-Bob' => {
    ...
                                              ]
                             }
            };
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-09-03 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls