Solved

perl code

Posted on 2004-08-25
5
147 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cpan issue 1 61
Check file date before getting folder path 1 64
How to search multiple patterms in a file with perl? 4 79
Vb script to unzip a files and rename the files 12 97
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now