in reply to Convert date

If you just need to convert the date without any validation, why not do

my $date = '20080501'; $date =~ s/^(\d{4})(\d{2})(\d{2})$/$1-$2-$3/;

Replies are listed 'Best First'.
Re^2: Convert date
by Anonymous Monk on Jul 15, 2009 at 09:29 UTC
    Why does the line print Use of uninitialized value in substitution (s///) How to avoid it

      The following code does not print any warning for me:

      >perl -wle "my $date='20080501'; $date =~ s/^(\d{4})(\d{2})(\d{2})$/$1 +-$2-$3/;print $date" 2008-05-01

      So the problem must be with your other code and/or how you're using it. My guess is that $date in your case is not defined. Print out $date before trying a substitution on it:

      print "I think \$date is [$date]\n";