[Gllug] Regexp

Alain Williams addw at phcomp.co.uk
Thu Mar 7 16:35:52 UTC 2002


On Thu, Mar 07, 2002 at 03:48:32PM -0000, Jackson, Harry wrote:
> 
> 
> > -----Original Message-----
> > From: Alain Williams [mailto:addw at phcomp.co.uk]
> > 
> > How about
> > 
> > $namelist = join ':', @name;
> > if/^$namelist/
> > 
> > Or do you want to do something completely different ?
> 
> Sorry I was a bit vague. I have a list of items in an array and each one of
> these items are a valid match.
> 
> @name = ("E1X","Z42","F11","34F");
> @name2 = ("EX","Z242","F1wdf1","32344F");
> 
> The arrays are quite big and the letters bear no relation to each other. I
> then want to check if these letters will appear in a line and output if
> possible.
> 
> if /^@name\/@name2\/@name3$/
> 
> etc etc
> 
> Any single entry from each array will match. The more I look at it the more
> I can see that you cannot put an array in a regular expression without some
> jiggery pokery. I will do it another way

An array is the wrong data structure, use a hash:
	my %name;
	my %name2;
	# Maybe insert values:
	foreach my $v (@name) {
		$name{$v} = 1;
	}

	# Parse the input line:
	my ($f1, $f2, $f3) = /%(.*)\/(.*)\/(.*)$/;
	if(defined($name{$f1}) and defined($name2{$f2}) and defined($name3{$f3}))
		....

-- 
Alain Williams

#include <std_disclaimer.h>

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list