> If I have a string, for examle: $date = "06072002";
> How could I separate this in to three separate vars so that $mon=06,
> $day=07 and $year=2002.

What do you have?  You have two digits, and two digits, and four digits.

In regex talk, that looks like this:

/(\d\d)(\d\d)(\d\d\d\d)/
or
/(\d{2})(\d{2})(\d{4})/

If that's the entire string, you'll want to use anchors to make sure
that you don't accidentally match things you shouldn't:

/^(\d\d)(\d\d)(\d\d\d\d)$/

So to put it together:

my $date = "06072002";

$date =~ /^(\d\d)(\d\d)(\d\d\d\d)$/
    or die "This doesn't look like a date: $date";

my ($month,$day,$year) = ($1,$2,$3);

xoxo,
Andy

-- 
'Andy Lester        [EMAIL PROTECTED]
 Programmer/author  petdance.com
 Daddy              parsley.org/quinn   Jk'=~/.+/s;print((split//,$&)
                            [unpack'C*',"n2]3%+>\"34.'%&.'^%4+!o.'"])

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to