Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Converting MySQL datetime values to DateTime objects (regex)

by LanceDeeply (Chaplain)
on Jul 14, 2003 at 20:46 UTC ( [id://274159]=note: print w/replies, xml ) Need Help??


in reply to Re: Converting MySQL datetime values to DateTime objects (regex)
in thread Converting MySQL datetime values to DateTime objects

what am i doing wrong here? i've tried it w/ and w/o the parens around the regexp.
use strict; use warnings; my $when = '2003-07-14 21:39:26.357'; my ( $yr, $mo, $day, $hr, $min, $sec ) = ( $when =~ /(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/ ); print "( $yr, $mo, $day, $hr, $min, $sec )\n"; __DATA__ Use of uninitialized value in concatenation (.) or string at C:\dev\sc +ripts\reg.pl line 6. Use of uninitialized value in concatenation (.) or string at C:\dev\sc +ripts\reg.pl line 6. Use of uninitialized value in concatenation (.) or string at C:\dev\sc +ripts\reg.pl line 6. Use of uninitialized value in concatenation (.) or string at C:\dev\sc +ripts\reg.pl line 6. Use of uninitialized value in concatenation (.) or string at C:\dev\sc +ripts\reg.pl line 6. Use of uninitialized value in concatenation (.) or string at C:\dev\sc +ripts\reg.pl line 6. ( , , , , , )
can somebody help a (clueless) brother out?
Update:
cool cool cool- never knew you could return an array from a regexp. here's another way too:
my ( $yr, $mo, $day, $hr, $min, $sec ) = ( $when =~ /(\d{4})\D*(\d\d)\D*(\d\d)\D*(\d\d)\D*(\d\d)\D*(\d\d)/ );

Replies are listed 'Best First'.
Re: Re: Re: Converting MySQL datetime values to DateTime objects (regex)
by dws (Chancellor) on Jul 14, 2003 at 20:52 UTC
    my $when = '2003-07-14 21:39:26.357'; my ( $yr, $mo, $day, $hr, $min, $sec ) = ( $when =~ /(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/ );
    You have to match all of the punctuation in your source string. E.g., to match
    my $when = '2003-07';
    you would use
    my ($yr,$mo) = $when =~ /^(\d\d\d\d)-(\d\d)/; ^
    Fixing the complete regex is a variation on this theme.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://274159]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-03-28 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found