string compare problem

P

pc

I have field1 and field3 contain date time values in form of a
string.For example:10/3/2006 8:02:49 ,10/3/2006 8:16:40.I break them
into 2 seperate date and time fields like this:

($datepart1,$timepart1) = split ' ', $field1;
($datepart3,$timepart3) = split ' ', $field3;

Now I want to check if the value of datepart1 and datepart3 are
unequal.


if($datepart1 ne $datepart3){
print ERROR;
}


This "if code" doesnt seam to work.When i print the values of
datepart1 and datepart3 before entering the if loop,they are not equal
but stilll the error message does not get printed on the screen.
 
L

Lars Eighner

In our last episode,
the lovely and said:
I have field1 and field3 contain date time values in form of a
string.For example:10/3/2006 8:02:49 ,10/3/2006 8:16:40.I break them
into 2 seperate date and time fields like this:
($datepart1,$timepart1) = split ' ', $field1;
($datepart3,$timepart3) = split ' ', $field3;
Now I want to check if the value of datepart1 and datepart3 are
unequal.

if($datepart1 ne $datepart3){
print ERROR;
}

This "if code" doesnt seam to work.When i print the values of
datepart1 and datepart3 before entering the if loop,they are not equal
but stilll the error message does not get printed on the screen.

What is ERROR?
 
P

pc

The error is that even though the values of datepart1 and datepart3
are not equal the message "ERROR" does not get printed on screen.
For example say field1=7/31/2007 7:39:22 and field3=7/30/2007
8:11:02.Now when I do

($datepart1,$timepart1) = split ' ', $field1;
($datepart3,$timepart3) = split ' ', $field3;
if($datepart1 ne $datepart3){
print ERROR;
}


I expect that the message "ERROR" prints on the screen.My problem is
that it doesnt.
 
L

Lars Eighner

In our last episode,
the lovely and talented pc
broadcast on comp.lang.perl.misc:
The error is that even though the values of datepart1 and datepart3
are not equal the message "ERROR" does not get printed on screen.
For example say field1=7/31/2007 7:39:22 and field3=7/30/2007
8:11:02.Now when I do
($datepart1,$timepart1) = split ' ', $field1;
($datepart3,$timepart3) = split ' ', $field3;
if($datepart1 ne $datepart3){
print ERROR;
}

I expect that the message "ERROR" prints on the screen.My problem is
that it doesnt.

Then make it a string, because the value of ERROR is empty, whereas
the value of 'ERROR' is ERROR.
 
P

pc

In Perl, you need to enclose strings in some sort of quotes:

print "ERROR";
print 'ERROR';
print q(ERROR);
print qq(ERROR);

If you had put 'use warnings;' at the beginning of your program, Perl
would have told you why your program isn't doing what you think it
should be.

Thank you Jim and Lars!
 
B

Ben Morrow

Quoth Lars Eighner said:
Then make it a string, because the value of ERROR is empty, whereas
the value of 'ERROR' is ERROR.

No, ERROR calls the sub ERROR; unless it doesn't exist and use strict
'subs' is not in effect, when it is autoquoted to 'ERROR'.

The OP is probably not using strictures (tut).

Ben
 
X

xhoster

Ben Morrow said:
No, ERROR calls the sub ERROR; unless it doesn't exist and use strict
'subs' is not in effect, when it is autoquoted to 'ERROR'.

In this case, ERROR is a file handle (probably not an open one), not a sub
call, and $_ is being printed to it.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top