This might not be a bad way to go if you are the only one who ever uses this script. But I'd think a series of splits combined with a clear "if" rather than the embedded ? will make the code a lot clearer and perhaps execute more quickly.
my $time_stamp = "2-19-01 3:22 PM";
my($date, $time, $am_pm) = split(/ /, $time_stamp);
my($month, $day, $short_year) = split(/-/, $date);
my($hours, $min) = split(/:/, $time);
if ($am_pm =~ /pm/i) {
$hours += 12;
}
my $year = 2000 + short_year;
my $sql_time_stamp = "$year-$month-$day $hours:$min"
I know this looks a lot more like "baby talk Perl", but ask yourself which one you can read more easily without background info. Also ask yourself which one is easier to change if your date format (into or out of this function) ever changes.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|