Not the fastest code, but is easy to read.
# grepasskey
# This function greps for a certain string in just the key. All
# elements with matching keys are returned.
sub grepasskey {
my($base) = shift(@_);
my(%ret);
my(%array) = @_;
my(@array) = sort(keys(%array));
my($i,$count);
foreach $i (sort (keys(%array))) {
if( hay($array[$count],$base)) {
$ret{$array[$count]} = $array{$i};
}
$count++;
}
return(%ret);
}
# hay(<@to_be_searched>,<searchfor>)
sub hay {
# $_@= string to search
# last element substring we are looking for in $_@
# returns a 1 if found
# returns a 0 if not found
my($searchfor) = pop(@_);
my($v); for($v=0;$v<@_;$v++) {
if( index($_[$v],$searchfor) != -1) {return(1);}
}
return(0);
}
---
[EMAIL PROTECTED] (Galactic Hero)
Diplomacy: The art of saying good doggie
while searching for a big rock.
> -----Original Message-----
> From: Hans Holtan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 13, 2001 5:23 PM
> To: [EMAIL PROTECTED]
> Subject: regex on hash keys?
> Importance: Low
>
>
> Hi everyone,
>
> I'm a bit green, and I'm trying to split a large file into a hash. My
> problem is that the parts that I want to use as keys are a bit long
> (100-200 letters), and I will need to pull them out by the presence
> of certain substrings later. So my actual question is this, how do I
> retreive a slice from a hash based on substrings in their keys?
>
> Thanks for your help.