GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   perl gurus, string checking (https://gfy.com/showthread.php?t=102089)

Rip 01-23-2003 12:52 PM

perl gurus, string checking
 
So first off, I have never taken a lesson in C or perl, but am pretty good with most computer languages

I have come up with a stumbling block in a perl script that I am working on, in particular checking for equality in a string value, and am looking for help

I have a simple form with user choices

1; value = 'nochoice'
1; value = 'yes'
1; value = 'no'

form input is parsed
and handed to the subroutine

if ($value ne "nochoice") {$modifyfield = 26; $searchtext eq $value;}

which did not find true upon any value other than 'nochoice' (in otherwords i want the true value to function, on a choice of yes or no

so I added

$value =~ /$value/i ;

before the if statement to try and clean up any possible erroneous charactures or whatever, but it's still not working

what am i doing wrong, any ideas

(if this doesn't display in the forum, I'll try an imagelink)

FuqALot 01-23-2003 01:47 PM

Well...

if ($value ne "nochoice") {$modifyfield = 26; $searchtext eq $value;}

If you want $searchtext to be come equal to $value, you should use '$searchtext = $value' instead of '$searchtext eq $value'.

About the non trueing, what I would try is, try each value out and let the script print $value, or something like:
'print "x".$value."x"', so whatever is between the x's is the actual value of $value (so you're not missing any spaces and stuff), because maybe the =~ didn't clean up, and so you will end up seeing $value was actually '%nochoice', or something.

If printing and checking the $value still doesn't give any results, then instead of 'if ($value ne "nochoice")' try the following:
'if ($value !~ m/nochoice/)'.

boldy 01-23-2003 01:53 PM

hit me up ... :thumbsup

Rip 01-23-2003 02:48 PM

Thanks for your suggestion Fugalot , I'll play with it
the form input is multiple select, so the user cannot type in any variations, but I'll try what you're suggesting


thanks for the offer boldy, but I don't use icq 99% of the time

I am going to break down the script to a single program and run the subroutine only to see it I can sort it out

maybe it's the way that the variables are being parsed as well, I'll have to look at that closely

NetRodent 01-23-2003 02:50 PM

I must be missing something because I think what you're tring to do is incredibly easy.

Instead of:

if ($value ne "nochoice") {$modifyfield = 26; $searchtext eq $value;}

Use:

if ($value eq 'yes' || $value eq 'no') {$modifyfield = 26; $searchtext eq $value;}

Rip 01-23-2003 03:09 PM

Thanks netrodent, that'd work in this scenario, only because there are two variables, on other fields there are numerous form choices

I tried it, but it is not working whatsoever, which makes me think perhaps it's the way the form is being parsed or else the perl on my server is screwed up, however other scripts work fine... so I am going to do some cut and paste

(*fval) = @_ if @_ ;

local ($buf);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
}
else {
$buf=$ENV{'QUERY_STRING'};
}
if ($buf eq "") {
return 0 ;
}
else {
@fval=split(/&/,$buf);
foreach $i (0 .. $#fval){
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;

if (!defined($field{$name})) {
$field{$name}=$val;
}
else {
$field{$name} .= ",$val";

#if you want multi-selects to goto into an array change to:
#$field{$name} .= "\0$val";
}


}
}
return 1;

what do you think???

Rip 01-23-2003 03:12 PM

whoa, I think in pasting, I just saw a problem...

"if you want multiple selects...."

dumb da dumb dum, I am going to go have a coffee break and then try it ..... hopefully it will work... - but it's been two days and counting so far

fiveyes 01-23-2003 03:20 PM

Quote:

Originally posted by Rip
...I have a simple form with user choices

1; value = 'nochoice'
1; value = 'yes'
1; value = 'no'
...

Remember, option choices are not assigned to 'value', but to the NAME of the selection. Also, all your values are being stored in a hashed array- %field.

In other words, if you have 'SELECT NAME="selection" ', you need to use:

if ($field{'selection'} ne "nochoice") {$modifyfield = 26; $searchtext eq $field{'selection'};}

(edit to remove that second instance of $value, since it is never assigned. )

Rip 01-23-2003 03:27 PM

Thanks

I do have a variable assignment
$value = $field{'value'} ;

earlier in the program, but I'll also try your suggestion

I looked at the parse sub, and it does not seem exactly right to me either tho... maybe I am seeing things, but it does not look like som otheres I have seen

fiveyes 01-23-2003 03:30 PM

Quote:

Originally posted by Rip
Thanks

I do have a variable assignment
$value = $field{'value'} ;

earlier in the program, but I'll also try your suggestion

I looked at the parse sub, and it does not seem exactly right to me either tho... maybe I am seeing things, but it does not look like som otheres I have seen

OK, make that statement:
$value = $field{'NAME_OF_SELECT_AS_GIVEN_IN_THE_FORM'} ;

Rip 01-23-2003 03:41 PM

I appriciate the help very much believe me! :)

I have the variables
similar to this, but the variables correspond to the form and the script variables
$value1 = $field{'forminput1'} ;
$value2 = $field{'forminput2'} ;
$value3 = $field{'forminput4'} ;


The script is printing the correct input variable as a flag in the document, so I know that it is correct, and recieved from the form input

the problem I am having is the ability to process and compare the string equality within the subroutine beyond the if statement

damn frustrating, it is, because as far as I can see, I am doing everything by the book


All times are GMT -7. The time now is 12:19 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123