string compare problem
am 11.10.2007 01:16:09 von 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.
Re: string compare problem
am 11.10.2007 01:45:44 von Lars Eighner
In our last episode,
<1192058169.572978.247310@o80g2000hse.googlegroups.com>, the lovely and
talented pc broadcast on comp.lang.perl.misc:
> 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?
--
Lars Eighner
Countdown: 467 days to go.
What do you do when you're debranded?
Re: string compare problem
am 11.10.2007 01:52:59 von 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.
Re: string compare problem
am 11.10.2007 01:58:10 von Jim Gibson
In article <1192058169.572978.247310@o80g2000hse.googlegroups.com>, pc
wrote:
> 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.
>
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.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Re: string compare problem
am 11.10.2007 02:01:13 von Lars Eighner
In our last episode,
<1192060379.956734.72680@r29g2000hsg.googlegroups.com>,
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.
--
Lars Eighner
Countdown: 467 days to go.
What do you do when you're debranded?
Re: string compare problem
am 11.10.2007 02:02:46 von pc
On Oct 10, 4:58 pm, Jim Gibson wrote:
> In article <1192058169.572978.247...@o80g2000hse.googlegroups.com>, pc
>
>
>
>
>
> wrote:
> > 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.
>
> 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.
>
> --
> Jim Gibson
>
> Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------
> http://www.usenet.com- Hide quoted text -
>
> - Show quoted text -
Thank you Jim and Lars!
Re: string compare problem
am 11.10.2007 02:33:16 von Ben Morrow
Quoth Lars Eighner :
> 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
Re: string compare problem
am 11.10.2007 19:26:15 von xhoster
Ben Morrow wrote:
> Quoth Lars Eighner :
> > 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'.
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.