On Thu, 21 Mar 2002, Bruce A. Burdick, Jr. wrote:

> For a normalization scheme, I have match and replace strings stored in
> variables (because they vary, of course) brought in from XML files. The
> replace strings depend on what is found in the match string. The problem?
> The replacement string is taken literally no matter what variations I've
> tried. Some examples:
> 
>     $data = '[03/12/2002:14:19:50]'; # to become: '2002-03-12 14:19:50'
>     $match = '\[(\d\d)\/(\d\d)\/(\d{4}):(\d\d):(\d\d):(\d\d)\]';
>     $replace = '\3-\1-\2 \4:\5:\6';
> 
>     unless ( $data =~ s/$match/$replace/ )

  Take a look at the 'eval()' function -- perldoc -f eval will give you the
  details.  

  You may get what you want via: eval("\$data =~ s/$match/$replace/")
  (Escape the first $ because you want it to continue to be the variable
  itself, not the value of the variable; leave the others as-is because
  you want their values swapped in before the expression's evaluated)

  Eval is powerful fu, but can have its gotchas. Read up!

-- 
Fred Hicks <[EMAIL PROTECTED]>

Reply via email to