in reply to Pulling Date out of String

A lot of guessing, but it sounds like you're looking for something like this:

my ($month, $day, $year) = $line =~ / (Jan|Mar|Dec) # the month abbreviations we want \s+ # followed by one or more spaces (\d+) # then one or more digits \s+ # then one or more spaces (\d+) # then one or more digits /x;
To clarify: I'm not sure if you're always looking for the same month, an abbreviation, a series of months, or a series of month abbreviations. This little example will work for a series of month abbreviations. Substitute whatever you need for the (Jan|Mar|Dec). (Keep the parentheses).

Next, I'm assuming that by "fields" you mean space separators for the month and year, which always appear in that order, as numbers. If you meant something else by "fields", you need to be more specific. This statement will assign those three parts to the three variables $month, $day, and $year. (Assuming your input string is in $line.)

If you haven't seen it before, the /x at the end of the pattern allows embedding comments and whitespace. It increases readability a lot.

As I said, there's a lot of guessing here on my part. If you want to be more general (for example, being able to handle more date formats), take a look at the many date-handling routines on CPAN.

HTH

Replies are listed 'Best First'.
Re: Re: Pulling Date out of String
by GreatWhite (Novice) on Jun 30, 2001 at 18:55 UTC
    Thank you for the code. I have been able to get my script to work. Thanks again- GreatWhite "The only true wisdom is in knowing you know nothing." -Socrates