stuck and it's been awhile since I touched it

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I have a little program that generates links like this:

blahblah.url/cgi-bin/program.pl?someimg.gif

Now what I want to do in the program.pl is have it match someimg.gif to the existing flat database (at the moment just like the example I had before with whatever|something|someimg.gif| et cetera).

I keep running into problems with the matching. I think it's the .gif part. But I don't know.

The rest is done (lord help me) except for this one MAJOR little detail.

Can anyone help or point me in a better direction than pattern matching?

Suzanne

------------------
Zero Cattle
Suzanne
Tables DeMystified

They have: 850 posts

Joined: Jul 1999

code:

@array = ("whatever|something|someimg.gif|","whatever|something|someimg2.gif|");
$lookfor = "someimg.gif";

foreach $line (@array)
{
	if($line =~ m/$lookfor/)
	{
		print "Found\n";
	}
	else
	{
		print "Not Found\n";
	}		
}
[/code]

I am not sure if that is exactly what you wanted, but it will look for the $lookfor in each element in an array.  With the first element in the array, it outputed "Found", and for the next one, it outputed "Not Found".

Does that help at all?

------------------
click here to help save lives
http://www.wiredstart.com  : The Technology Start Page

[This message has been edited by robp (edited 13 May 2000).] 
Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Yes, that does help, thanks!

$lookfor in this case would be $ENV{QUERY_STRING}?

What I need to do is where you have print... in the if statement, is have a new variable set there.

So if the name is found (which it will be if they just click on the link, because the name is generated), then the item's location will be returned?

$lookfor = $array[$number][0]

I think I am coming at this the wrong way.

Hmmm.

Thanks for the response, I am going to go off and mutter to myself for awhile.

Suzanne

They have: 453 posts

Joined: Jan 1999

Hi,

why don't you use a hash ?
If you setup like this:
$array{ "wathever" } = "http://wherever/here.html";
.
.
.

Then you can just use:
print "Location: ".( $array{ $ENV{QUERY_STRING} } )." \n\n";

I'm not sure that this is what you want, but it works for me.

ciao
Anti

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I think that you are right -- at least that's what the Perl Cookbook asks when it tries to tell me how to do with without a hash.

*sigh*

I would be doing it that way, but I'm not up to that lesson yet. Guess it's back to the books for a moment.

Thanks very much for taking the time to drill commonsense into my head!

Suzanne

------------------
Zero Cattle
Suzanne
Tables DeMystified

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.