Gossamer Forum
Quote Reply
$value
I would like to do something like this:

if $value [begins with] "ab" {
print "The first two letters of $value are ab \n";
}
else
{
print "Doesn't begin with ab\n";
}

...what to put at []
Quote Reply
Re: $value In reply to
if it is always the first two letters you are looking at

if (substr($value,0,2) eq "ab") {

etc

--Mark

------------------
You can reach my by ICQ at UID# 8602162

Quote Reply
Re: $value In reply to
no, i want this alsow for an other reason,

I want to make a mod for my own goto.cgi, this because i not only have http:// adresses in my database but alsow "file=test.pdf"

So i want to search for file= delete file= fropm the value, and redirect to onother location like /cgi-bin.download.cgi?download=test.pdf&dag=monday

Can you help me?
Quote Reply
Re: $value In reply to
Another way to do the match, and I think this is preferred, would be to use a pattern match on the beginning of the string. Its also a good lesson in reg-expressions:

if ($value =~ m/^ab/i) {
print "The first two letters of $value are ab \n";
} else {
print "Doesn't begin with ab\n";
}
The "i" at the end checks regardless of case, if that is important to you, then remove it.

To do part two of your problem, we simply perform a split based on your value:

if ($value = m/^file/i) {
@line = split /=/, $value;
$file = $line[1];
} else {
# Do something else
}

Then perform the redirect as usual with CGI.pm or some other method you might have concocted, using the following:

"/cgi-bin/download.cgi?download=$file&dag=monday"

Let me know if this is too confusing.

------------------
Fred Hirsch
Web Consultant & Programmer
Quote Reply
Re: $value In reply to
so this would go into my jump.cgi


if ($value = m/^file/i) {
@line = split /=/, $value;
$file = $line[1];
print "Location: /cgi-bin/download.cgi?$file\n\n";
} else {
print "Location: $goto\n\n";
}


BUT how to put it into the jump.cgi beta3 ?


# Now let's send the user to the url..
$goto ?
print "Location: $goto\n\n" :
&error ("Record not found ($in{$db_key})");
}

[This message has been edited by chrishintz (edited January 06, 1999).]