Get hash contents without resetting each iterator

Edit Package perl-Hash-SafeKeys
https://metacpan.org/release/Hash-SafeKeys

Every hash variable in Perl has its own internal iterator, accessed by the builtin 'each', 'keys', and 'values' functions. The iterator is also implicitly used whenever the hash is evaluated in list context. The iterator is "reset" whenever 'keys' or 'values' is called on a hash, including the implicit calls when the hash is evaluated in list context. That makes it dangerous to do certain hash operations inside a 'while ... each' loop:

while (my($k,$v) = each %hash) {
...
@k = sort keys %hash; # Infinite loop!
@v = grep { /foo/ }, values %hash; # Ack!
print join ' ', %hash; # Run away!
}

'Hash::SafeKeys' provides alternate functions to access the keys, values, or entire contents of a hash in a way that does not reset the iterator, making them safe to use in such contexts:

while (my($k,$v) = each %hash) {
...
@k = sort safekeys %hash; # Can do
@v = grep { /foo/ }, safevalues %hash; # No problem
print join ' ', safecopy %hash; # Right away, sir
}

Refresh
Refresh
Source Files
Filename Size Changed
Hash-SafeKeys-0.04.tar.gz 0000009262 9.04 KB
perl-Hash-SafeKeys.changes 0000000192 192 Bytes
perl-Hash-SafeKeys.spec 0000002513 2.45 KB
Latest Revision
Dirk Stoecker's avatar Dirk Stoecker (dstoecker) accepted request 1066861 from Dirk Stoecker's avatar Dirk Stoecker (dstoecker) (revision 1)
For perl-Perl-LanguageServer update
Comments 0
openSUSE Build Service is sponsored by