Gossamer Forum
Home : General : Perl Programming :

Conditional giving me a condition!

Quote Reply
Conditional giving me a condition!
What is wrong with this if statement, it is driving me around the twist.

Code:
$action = $IN->param('B1');

if ($action == 'Editor') {
print "Depositing $amount1 to $editorname...";
#make sure editor exists
print " $action<br>";
}

It seems no matter what value $action is set to... it still performs the actions inside the if statment!! I proved that $action is not equal to 'Editor' with the included print statement.

Crazy


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jun 11, 2002, 12:49 PM
Quote Reply
Re: [Ian] Conditional giving me a condition! In reply to
'==' should be 'eq' - '==' tests numerically, 'eq' tests alphabetically.

Code:


== -> eq
!= -> ne
> -> gt
< -> lt
>= -> ge
<= -> le

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] Conditional giving me a condition! In reply to
I was just commenting to my girlfriend on what kind of perl guru you must be to whip out statements like:

@top3 = (sort { (split ',', $a, 3)[-1] <=> (split ',', $b, 3)[-1] } @array)[0 .. 2]; off the top of your head.

Thanks for the help!!!!


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Conditional giving me a condition! In reply to
If you are wondering what it does then instead of assigning everything to variables first, it just works "on the fly" so to speak.

[0 .. 2] means that only elements 0, 1 and 2 will be added to the array (only the top 3 were asked for).

(split ',', $a, 3)[-1] ....that splits the data and [-1] is the last element (which is the number that the user wanted to sort by)

Its always easy in retrospect Laugh

Last edited by:

Paul: Jun 11, 2002, 1:21 PM
Quote Reply
Re: [Paul] Conditional giving me a condition! In reply to
Thanks Paul, that makes sense. Obviously these kinds of statements are 2nd nature to you also.

In time I will be able to read it like my name. I find the string/array/regex type of statements to be the most interesting (and foreign) to me.

Something I will have to get my teeth into soonSmile


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Conditional giving me a condition! In reply to
>>Obviously these kinds of statements are 2nd nature to you also.<<

I'd like to think so but if they were I would have given that solution in my first reply but I didn't think of it :)

Looking back it is obvious though.