in reply to Re: String Substitution Operator
in thread String Substitution Operator

How do I :

convert a string in day-month-year format to the dd-mm-yy format?

I use :$string =~ s/(\W)/-/x;

But the book asks me to use: $string =~ s/\d{2} ([\W]) \d{2} \1 \d{2}/$1-$2-$3/x instead and hence the confusion, since the special variables $1 etc will just match the pattern in parentheses, does this not mean that $1,$2,$3 should just contain the hyphen and NOT the *day*,*month*,*year* values?

A related question is: if I do want to use the day,month,year values, how do I do that?

Thanks.

Replies are listed 'Best First'.
Re: Re: Re: String Substitution Operator
by hehenoobhehe (Novice) on Oct 23, 2003 at 08:47 UTC
    If I provide a string like "14/01/52", I want the output to be : "14-01-52".
      Simple.
      my $str = "14/01/52"; $str =~ s/\//-/g; # replace / with - print "$str\n";
      By using $string =~ s!/!-!g. The exclamation points prevent the "toothpick syndrome" (s/\//-/g is a little less readable).

      Arjen