bart has asked for the wisdom of the Perl Monks concerning the following question:
I'm parsing a database description for a Progress database, and I want to create an importer for Oracle for an exported flatfile. One of the fields is of the type "date". Now, at first sight, I find format specifications for dates like "99/99/9999", which should produce a format "DD/MM/YYYY", and "99/99/99", producing "DD/MM/RR", for use in a to_date() call. Note: "RR" specifies a 2 digit year, which will be considered in the range 2000-2049 if it's < 50, and between 1950 and 1999 if >= 50.
Simple enough, a conversion hash
would do... Except: I want to be able to accept other separators than slashes, too. The script should be smart enough to produce the appropriate format with the actual separators. In short, it should produce 'DD-MM-YYYY' out of '99-99-9999', for example.%dateformat = ( '99/99/99' => 'DD/MM/RR', '99/99/9999' => 'DD/MM/YYYY', '9999/99/99' => 'YYYY/MM/DD' );
Your assignment is to write some Perl code which does this conversion. A generic solution, using a data table for the production, is preferred over a hardwired solution, using a code block for each pattern.
I'll post a solution of my own in a follow-up, later.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Generating a format template for a date
by blazar (Canon) on Oct 13, 2006 at 16:46 UTC | |
by Hue-Bond (Priest) on Oct 13, 2006 at 17:17 UTC | |
|
Re: Generating a format template for a date
by duckyd (Hermit) on Oct 13, 2006 at 16:51 UTC | |
by davidrw (Prior) on Oct 13, 2006 at 17:49 UTC | |
|
Re: Generating a format template for a date
by jbert (Priest) on Oct 13, 2006 at 17:03 UTC | |
by davidrw (Prior) on Oct 13, 2006 at 17:52 UTC | |
by jbert (Priest) on Oct 13, 2006 at 18:01 UTC | |
|
Re: Generating a format template for a date
by MonkE (Hermit) on Oct 13, 2006 at 18:26 UTC | |
|
Re: Generating a format template for a date
by johngg (Canon) on Oct 14, 2006 at 11:29 UTC | |
|
Re: Generating a format template for a date
by bart (Canon) on Oct 15, 2006 at 22:33 UTC |