Copyright © tutorialspoint.com

# PERL keys Function

## Syntax

keys HASH

## Definition and Usage

Returns all the keys of the HASH as a list. The keys are returned in random order but, in fact, share the same order as that used by values and each.

## Return Value

- In scalar context - Number of keys in the hash

- In list context - List of keys

## Example

Try out following example:

    #!/usr/bin/perl

    %hash = ('One' => 1,
             'Two' => 2,
             'Three' => 3,
             'Four' => 4);

    @values = values( %hash );
    print("Values are  ", join("-", @values), "\n");

    @keys = keys( %hash );
    print("Keys are ", join("-", @keys), "\n");

It will produce following results:

    Values are  4-3-2-1
    Keys are Four-Three-Two-One

Copyright © tutorialspoint.com