On Aug 1, 5:02 am, [EMAIL PROTECTED] (Jeevs) wrote:
> Before reading the above comments I used the localtime function of
> Time::Local to convert the dates into epochs and then comparing
> numerically.
>
> But thanks as i was not knowing that the strings i.e 2007-12-01 and
> 2007-12-02 can be compared using the string operators for dates. Can
> anyone point me to how strings are compared. To be more ellaborate i
> can understand if strings like 2007-12-01 is less than 2007-12-02 but
> how can a string 2007-11-01 will be less than 2007-12-01 .

"2007-12-01" vs "2007-11-01"
"2" vs "2", even, move on
"0" vs "0", even, move on
"0" vs "0", even, move on
"7" vs "7", even, move on
"-" vs "-", even, move on
"1" vs "1", even, move on
"2" vs "1".  2 is "greater" (it's ASCII chart number is higher) than
1.  Therefore, 2007-12-01 is greater than 2007-11-01.

Basically strings compare left to right, character by character, until
a difference is found.  It then goes by the ASCII chart (or whatever
encoding is currently in place) to decide which is greater.

Note that the undefined string-equivalent to the empty string, which
is less than all non-empty strings.  And a starting substring is less
than its parent string:

$ perl -MData::Dumper -le'
my @stuff = ("foobar", "foo", "\0", undef, "", undef);
$Data::Dumper::Useqq = 1;
print Dumper([sort @stuff]);
'
$VAR1 = [
          undef,
          "",
          undef,
          "\0",
          "foo",
          "foobar"
        ];

Oddly, I can't actually find the reference that states this
explicitly...

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to