Solved

perl code

Posted on 2004-08-25
5
153 Views
Last Modified: 2010-03-05
hi..
i have this statment in the perl script that allows me to extract the date "02/31/04"
and insert it to the database in the form of "2004/02/31"
this is the statment :
  if( /Start Date\s*:\s*(\S+)/ ) {
    $job = $1;
    ($date = $2) =~ s!(\d\d)/(\d\d)/(\d\d)!20$3/$1/$2!;

however, the date formate given  is in this form "thur jul 22 10:10:18 2004"
how do i modify the above statment to extract onlt "jul 22 2004"

thanks.
0
Comment
Question by:TPoly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 11899752
s/\w+\s+(\w+)\s+(\d+)\s+\d\d:\d\d:\d\d\s+(\d\d\d\d)/$1 $2 $3/;
0
 

Author Comment

by:TPoly
ID: 11899822
hi ozo,
 i tried the statement you have provided but it only extract "thur" and
insert it into the database.
0
 

Author Comment

by:TPoly
ID: 11899839
sorry..
my mistake i want to modify the above perl statement from
"thur jul 22 10:10:18 2004" to "2004/07/22"
0
 
LVL 84

Accepted Solution

by:
ozo earned 200 total points
ID: 11899893
$_="thur jul 22 10:10:18 2004";
@m{qw(jan feb mar apr may jun jul aug sep oct nov dec)}=('01'..'12');
 s!\w+\s+(\w+)\s+(\d+)\s+\d\d:\d\d:\d\d\s+(\d\d\d\d)!$3/$m{$1}/$2!;
print;
0
 

Author Comment

by:TPoly
ID: 11900059
hi ozo. the state ment work,
however it is unable to insert the date into the database and
also i have have duplicate dates but i have many text files
with different date.
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question