Gossamer Forum
Home : General : Perl Programming :

compare numbers

Quote Reply
compare numbers
Ok I am defeated , I have tried this for over a week and failed ...so please someone tell me why ?

$diskmb_flopdate ="2006";
if ($diskmb_flopdate < 2004) {
}&asub;
exit;

This should run onto the next print" statment : but its not .

I tried an else {..... and I tried another 'if statment in reverse added below to do the opposite ie ;
if ($diskmb_flopdate > 2004) {
}& a different sub ;
exit;

I am actually trying to compare one number against another (yeah you guessed it ('a years date') to divert to either the correct sub or print" statement , if the year is more (a higher number 2006 , the code should go one place and if its less 2003 then it should go elsewhere .
Quote Reply
Re: [classca] compare numbers In reply to
I'm confused as to what is not working?

Try soemthing like;

Code:
my $date = 2006;
if ($date <= 2003) {
print "Year is less than or equal to 2003";
} else {
print "Year is greater than 2003";
}

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] compare numbers In reply to
U and I alike Andy , I pretty much tried every combination including (now) 'my' $date as you have suggested and that has brought a refresh page (I was getting that a lot with my own efforts) .

Still Glad I am not alone here with this mind boggler .

Ok, unless you or someone else has any other solutions .....my next idea will be to move the position of the code elsewhere in the script and try that . (always the final thing to do .)

Mainly, I just wanted to check with someone else the Code in general ,for confirmation that I wasn't going completely mad .

Thankyou Andy very much for your help .
Quote Reply
Re: [classca] compare numbers In reply to
No problem.

What is the exact code you are using? You should really start using "strict", which is where the 'my' stuff starts coming in. This helps pick problems up, with typos in variable names, etc. Saves me hours of debugging time each week :)

Code:
#!/us/bin/perl

use strict;
use CGI;
my $IN = new CGI;

print $IN->header();

my $date = '2006';
if ($date <= 2003) {
print "Year is less than or equal to 2003";
} else {
print "Year is greater than 2003";
}

That seems to work ok for me :/

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] compare numbers In reply to
Thanks again Andy , and again I have wound myself up into a tizzy ....(gonna throw something anytime now)


I tried the simple the complicated you name it .

Even took your code and copied it .

I used use CGI::Carp qw(fatalsToBrowser);

to get compilation errors (helpful)

This is the sub and the damn thing wont work !

$diskmb_flopdate=$FORM{'diskmb_flopdate'};

sub upgrade {
print "content-type: text/html\n\n";
$diskmb_flopdate = '2005';
if ($diskmb_flopdate < = '2003') {
}&hello;}
else {
print"anything";
}

stumped ......
Quote Reply
Re: [classca] compare numbers In reply to
What is this part meant to be doing? Unsure

Code:
}&hello;}

Try the following; (you were *so* close)

Code:
sub upgrade {

print "content-type: text/html\n\n";
$diskmb_flopdate = '2005';

if ($diskmb_flopdate < = '2003') {
&hello;
} else {
print"anything";
}

}

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] compare numbers In reply to
&hello

only just goes to an empty 'sub' with hello printed .so as I can see if its working .


makes no difference if it goes to anywhere really Andy .

It actually (*should I ever resolve the problem , it will go to a sub that shows other options for the user .


I must admit it at this point I am beaten ...I have even broke the whole thing down to just a form and an emty cgi ...bar, the little bit of code ...and still the bugger wont work !


If you got it to work Andy ? from a form to the script ?
I would apreaciate a copy , or seeing it working , whatever ...its driving me nuts .

<form action="to script "method=post>

<input type=hidden name="action" value="upgrade">
<input type="submit" class=buttons value="upgrade">
</form>

My email address is david@thewebuilders.co.uk I am in London UK

Last edited by:

classca: Jun 19, 2004, 7:47 AM
Quote Reply
Re: [classca] compare numbers In reply to
I don't think you are understanding me correctly :( The part in red is in the wrong place;

sub upgrade {
print "content-type: text/html\n\n";
$diskmb_flopdate = '2005';
if ($diskmb_flopdate < = '2003') {
}&hello;}
else {
print"anything";
}


... it should be;

sub upgrade {
print "content-type: text/html\n\n";
$diskmb_flopdate = '2005';
if ($diskmb_flopdate < = '2003') {
&hello;}
else {
print"anything";
}

...note the missing } (which wasn't required).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] compare numbers In reply to
Thanks Andy , I am sure I will sort it out in time ...ofcourse it's not the bracket , that was probably an error at that moment ...as I said I have tried many orientations and have yet to find the solution or problem .

Someone else may spot it ...before I eventually strip the whole script to bare bones .

Thank you once again for all you effofts ...it is very much apreaciated , I am not one to ask out as a rule , but I was foxed .(still am ) .
Quote Reply
Re: [Andy] compare numbers In reply to
Remarkably enough today ....sorted no problems ...it took me about 1 hr from scratch . Bare bones bottom up .

Thank you for your time yesterday Andy ...boy I had a bad scripting day-week LOL .

Actually the problem was a simple one , as they generally are ,you know how it is ........


www.webezi.com

Last edited by:

classca: Jun 20, 2004, 6:38 AM
Quote Reply
Re: [classca] compare numbers In reply to
In Reply To:
Actually the problem was a simple one , as they generally are ,you know how it is ........

[/url]

So what was it?
Quote Reply
Re: [CrazyGuy] compare numbers In reply to
I'm still a little baffled as to why my code didn't work. I tried it, and it worked perfectly Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] compare numbers In reply to
I was just interested to see if it was possible to close the loop for the benefit of future searchers.

If it was me, I'd have been looking to see if something had happened that made perl treat one of the variables as a number and the other as a string, 'cos I've been caught out like that before. Comparing apples with oranges in real life is hard enough, doing it in Perl is rarely fruitful Crazy