Re: How to chck for string in array elements
- From: Ian Wilson <scobloke2@xxxxxxxxxxxxx>
- Date: Thu, 23 Feb 2006 11:05:03 +0000 (UTC)
folkvord@xxxxxxxxx wrote:
Hi!
I am trying to make an index of a lot of textfiles. Since the index
thends to get quite large, I want to optimize my algorithm som that if
$string is a part of a element already stored in @words it won't be
added to the array.
As an example:
my @words=qw(this is just an example of words);
$string = "his";
Since "his" is a substring of "this", it shouldnt be neccessary to
index it.
Your assertion seems strange to me, "his" is a valid English word that I'd expect to be able to look up in an index. Presumably you know what you are doing?
But I cant figure out an efficient way to check if $string is
a substring of an element in the array.
Can anyone give me a hint her, please ?
I've no idea how efficient it is, but maybe this counts as a hint?
#!/usr/bin/perl
use strict;
use warnings;
my @words=qw(this is just an example of words);
my $string = "his";
for my $word (@words) {
if ($word =~ /$string/) {
print "$string is a substring of $word\n";
}
}
You may need to post a minimal but complete working example of your current code if you need help optimising it.
HTH
.
- Follow-Ups:
- Re: How to chck for string in array elements
- From: folkvord
- Re: How to chck for string in array elements
- References:
- How to chck for string in array elements
- From: folkvord
- How to chck for string in array elements
- Prev by Date: FAQ 4.14 How can I compare two dates and find the difference?
- Next by Date: Re: How to chck for string in array elements
- Previous by thread: Re: How to chck for string in array elements
- Next by thread: Re: How to chck for string in array elements
- Index(es):
Relevant Pages
|