• Perl
  • 43 lines
  • 25 views
  • 2 forks
  • Pasted by anonymous on April 30, 2012
#!/usr/bin/env perl6

my %users =
    'alice' => {
        'email' => 'alice@example.com',
        'pwd' => 's3cr3t',
        'aliases' => ['al', 'allie', 'alster']},
    'bob' => {
        'email' => 'bob@example.com',
        'pwd' => 'abc123',
        'aliases' => ['bob-o', 'Mr. Bob']},
    'charlie' => {
        'email' => 'charlie@example.com',
        'pwd' => 'dog',
        'aliases' => ['Chaz', 'C-ward']};

# Change charlie's password to "change-me".
say "Old password: %users<charlie><pwd>";
%users<charlie><pwd> = 'change-me';
say "New password: %users<charlie><pwd>";

# Add alias "Robert" for bob.
say "bob's aliases: %users<bob><aliases>";
%users<bob><aliases>.push('Robert');
say "bob's aliases: %users<bob><aliases>";

say '-' x 42;

# Print out all user info.
for %users.keys -> $name {
    for %users{$name}.kv -> $k, $v {
        if $k ~~ 'aliases' {
            say "$k:";
            # print out aliases, one per line.
            for $v -> $alias {   # XXX <--- wait, but $v should be an array...
                say "\t$alias";
            }
        }
        else {
            say "$k:\t$v";
        }
    }
}

Did you know? CLOSE

  • There are keyboard shortcuts!
    • When Creating A Paste
      • ALT+P Toggle Private
      • CTRL+Enter Create Paste
      • ALT+W Toggle word wrap
    • When Viewing A Paste
      • ALT+G Go to a line
      • ALT+CTRL+E Edit the paste
      • ALT+R Show the raw code
  • There are URL options!
    • When Creating A Paste
      • ?lang=Javascript to default to javascript
    • When Viewing A Paste
      • #L-N Jump to line number N
?