Gossamer Forum
Home : General : Perl Programming :

Stupid Array!

Quote Reply
Stupid Array!
I'm trying to go through each line in a HTML page, and check if it contains any of the entries within the array. If it does, then 'push' it to annother array, used later when joined back together as a string.

At the moment I have;

Code:
my @avs_list = qw("Word1" "word 2" "word 3" "word 4");

foreach (@html) {
foreach my $list (@avs_list) {
if (/$list/i) {
push(@avs, "$list");
}
}
}

$AVS = join(", ", @avs);

The problem I am having, is that, for example only 'word' out of 'the "word 1" array entry was found, it will push the whole thing. I want it to ONLY add that entry if the whole phrase was found Unsure

Any ideas? I've tried several things...but none seem to work Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Stupid Array! In reply to
I *think* this question is answered in the Perl FAQ. Maybe this will help?:

http://www.perlfaq.com/...n/view?view_by_id=99

- wil
Quote Reply
Re: [Wil] Stupid Array! In reply to
Don't think it does Unsure I *think* it is something with the regex, rather than the actual Array itself...

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Stupid Array! In reply to
Well, I guess so. For a start:

if (/$list/i) {

Is not what you want.

You need to define $_ here to make things easier:

foreach (@html) {

So you can do:

if ($list eq $earlier_defined_variable)

- wil
Quote Reply
Re: [Andy] Stupid Array! In reply to
I'm a bit confused about what you are saying...but does this work?

Code:
my @avs_list = ("Word 1", "word 2", "word 3", "word 4");

foreach my $html (@html) {
foreach my $list (@avs_list) {
push(@avs, $list) if ($html =~ /$list/i);
}
}

That should work fine unless I've totally misunderstood your problem.

Last edited by:

Paul: Oct 9, 2002, 2:52 AM