File: Util.pm

package info (click to toggle)
libgraph-easy-perl 0.76-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,264 kB
  • sloc: perl: 23,869; makefile: 7
file content (51 lines) | stat: -rw-r--r-- 733 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package Graph::Easy::Util;

use strict;
use warnings;

use base 'Exporter';

our @EXPORT_OK = (qw(first_kv ord_values));

use List::Util qw(minstr);

=head1 FUNCTIONS

=head2 first_kv($hash_ref)

The first key value pair from a hash reference - lexicographically.

=cut

sub first_kv
{
    my $href = shift;

    my $n = minstr( keys(%$href) );
    my $v = $href->{$n};

    return ($n, $v);
}

=head2 ord_values($hash_ref)

The values of the hash ordered by a lexicographical keyname.

=cut

sub ord_values
{
    my $href = shift;

    if ((!defined $href) || (! %$href))
    {
        return (wantarray ? () : 0);
    }
    else
    {
        return (wantarray ? @{$href}{sort keys( %$href )} : scalar(keys(%$href)));
    }
}

1;