Yang
Yang

Reputation: 1333

what Perl will take to compare in this case?

Just interested at this kind of comparison, any clue?

Say there are two variables as below:

$p1 = "2013-01-11/2013-01-04";
$p2 = "2013-01-12/2012-01-05";

If like below codes in Perl,

if $p1 lt $p2

What Perl will take to compare and how?

Upvotes: 1

Views: 108

Answers (2)

foundry
foundry

Reputation: 31745

Breaking down your tasks:

  • separate your strings into (start_stringtime, end_stringtime) string pairs
  • convert each string in the string pair into a datetime
    (there's a gazillion modules for this, choose one(s) appropriate for your task)
  • calculate the time periods for each pair
  • compare the time periods numerically - if $p1 < $p2

This question:
Convert string "20-May-07" to date and manipulate

will give you some leads

Upvotes: -1

Summer_More_More_Tea
Summer_More_More_Tea

Reputation: 13456

lt is string comparation operator, and it compares two operands in their literal sense.

In your case, two strings

2013-01-11/2013-01-04
||||||||||
2013-01-12/2012-01-05

will be compared in the illustrated manner, and stop at the 9th position (the first position characters are different, also note string index starts at 0), i.e. 1 in $p1 and 2 in $p2. And also 1 is less than 2 literally. So $p1 lt $2 is true.

Upvotes: 7

Related Questions