Home > Archive > PERL Beginners > November 2007 > Checking the two variable
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Checking the two variable
|
|
| Sivasakthi 2007-11-17, 4:01 am |
| Hi all,
I have the two variables, like below,
$val1=[15/Apr/2005:11:46:35 +0300];
$val2=[12/Nov/2007:14:59:00 +0530];
I want to check these two variables are equal or not.. I know the method
of splitting the each column and compare it.. but it too large.. is it
possible to check with easily??
Thanks,
Siva
| |
| Jeff Pang 2007-11-17, 4:01 am |
| the simplest way:
if ( $val1 eq $val2 ) {
do something...
} else {
do another thing...
}
but, since this is a datetime string, for better control, you may want
to take the way of comparing them with time. see some modules like
Time::Local.
On Nov 17, 2007 12:36 PM, sivasakthi <msivasakthi@gmail.com> wrote:
> Hi all,
>
> I have the two variables, like below,
>
> $val1=[15/Apr/2005:11:46:35 +0300];
> $val2=[12/Nov/2007:14:59:00 +0530];
>
> I want to check these two variables are equal or not.. I know the method
> of splitting the each column and compare it.. but it too large.. is it
> possible to check with easily??
>
>
> Thanks,
> Siva
>
| |
| Rob Dixon 2007-11-17, 7:00 pm |
| sivasakthi wrote:
> Hi all,
>
> I have the two variables, like below,
>
> $val1=[15/Apr/2005:11:46:35 +0300];
> $val2=[12/Nov/2007:14:59:00 +0530];
>
> I want to check these two variables are equal or not.. I know the method
> of splitting the each column and compare it.. but it too large.. is it
> possible to check with easily??
What you've written isn't valid Perl, so I shall have to guess at what
you might mean. If you have two strings like this
$val1 = '15/Apr/2005:11:46:35 +0300';
$val2 = '12/Nov/2007:14:59:00 +0530';
then you can compare them with eq, like this
print "equal" if $val1 ne $val2;
but you say they are "too large". What do you mean by that please?
Rob
| |
| Sivasakthi 2007-11-19, 4:02 am |
|
>
> What you've written isn't valid Perl, so I shall have to guess at what
> you might mean. If you have two strings like this
>
> $val1 = '15/Apr/2005:11:46:35 +0300';
> $val2 = '12/Nov/2007:14:59:00 +0530';
>
> then you can compare them with eq, like this
>
> print "equal" if $val1 ne $val2;
>
> but you say they are "too large". What do you mean by that please?
>
> Rob
I thought we should compare only possible by splitting the $val1 and
$val2 in to date, month,year.. after that first compare the year and
then month,date , finally compare the timings.. for that we need to
split first with ':' separator and then split with '/' separator ..
that's why i told it takes too large..
but you have solved my problem.. if suppose i will check both are less
than or greater than then the above solution is not suitable??
Thanks,
Siva
| |
| Dr.Ruud 2007-11-19, 10:02 pm |
| sivasakthi schreef:
> I have the two variables, like below,
>
> $val1=[15/Apr/2005:11:46:35 +0300];
> $val2=[12/Nov/2007:14:59:00 +0530];
In stead of using such numbers in variable names, use an array.
my @dates;
$dates[0] = q[15/Apr/2005:11:46:35 +0300];
$dates[1] = q[12/Nov/2007:14:59:00 +0530];
> I want to check these two variables are equal or not.. I know the
> method of splitting the each column and compare it.. but it too
> large.. is it possible to check with easily??
Define 'equal'. Are these meant to be strings, or maybe DateTime values?
(look for DateTime modules on CPAN)
--
Affijn, Ruud
"Gewoon is een tijger."
|
|
|
|
|