On Aug 13, Birgit Kellner said: >Hm, what's the shortest way to do this: I have a hash where one, and only >one, key begins with a number, I don't know its value and want to assign >this value to a variable. Loop over the keys, using keys() or each(). for (keys %hash) { $wanted = $hash{$_}, last if /^\d/; } or while (my ($k, $v) = each %hash) { $wanted = $v, last if $k =~ /^\d/; } -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: finding a key in a hash with regexp
Jeff 'japhy/Marillion' Pinyan Sun, 12 Aug 2001 17:14:10 -0700
- finding a key in a hash with regexp Birgit Kellner
- Re: finding a key in a hash with regexp Eric Beaudoin
- Re: finding a key in a hash with regexp Jeff 'japhy/Marillion' Pinyan
- Re: finding a key in a hash with regexp Michael Fowler
- RE: finding a key in a hash with regexp Faux, David