Monks!
a.newbie
i'm working on a small web site where a text input should be pattern matched and all date formats such as(dd/mm/yyyy | dd-mm-yyyy) should converted into say :'01st January 2003'. I managed to do that(with the help of the Monastery) using memory parenthesis($1,$2 etc). The problem is i can apply it to the code only once,thus it matches and converts only the first match...
this is the code:
#!perl
use CGI;
$query = new CGI;
$source = $query->param('input');
print $query->header,
$query->start_html('10222161'),
$query->h1({-align=>center},'CAD Assignment 1B'),
$query->p({-align=>center},'The corrected text is: '),
$query->hr;
$source =~ m!(\d{1,2})(\/|\-)(\d{1,2})(\/|\-)(\d{2,4})!g;
my $day = $1;
my $month = $3;
my $year = $5;
if($day == 1 or $day == 21 or day == 31){
$day .='st';
} elsif ($day == 2 or $day == 22){
$day .='nd';
} elsif ($day == 3 or $day == 23){
$day .= 'rd';
} else {
$day .= 'th';
}
if($month == 01){
$month = 'January';
} elsif ($month == 2){
$month = 'February';
} elsif ($month == 3){
$month = 'March';
} elsif ($month == 4){
$month = 'April';
} elsif ($month == 5){
$month = 'May';
} elsif ($month == 6){
$month = 'June';
} elsif ($month == 7){
$month = 'July';
} elsif ($month == 8){
$month = 'August';
} elsif ($month == 9){
$month = 'September';
} elsif ($month == 10){
$month = 'October';
} elsif ($month == 11){
$month = 'November';
} else {
$month = 'December';
}
print $query->p({-align=>center},"$day $month $year"),
$query->hr,
$query->i({-align=>center},'10222161'),
$query->end_html;
Many thanks in advance!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.