[sf-perl] Quick question on regular expression and substitution

Adam Morgan Adam.Morgan at safeway.com
Wed Jun 28 10:34:50 PDT 2006


The solution I sent has no dependency on what comes after and so may be
well suited to your problem. 

-----Original Message-----
From: sanfrancisco-pm-bounces+adam.morgan=safeway.com at pm.org
[mailto:sanfrancisco-pm-bounces+adam.morgan=safeway.com at pm.org] On
Behalf Of Loo, Peter # PHX
Sent: Wednesday, June 28, 2006 10:05 AM
To: San Francisco Perl Mongers User Group
Subject: Re: [sf-perl] Quick question on regular expression and
substitution


Hi David,

The problem is I won't know what position I need to change.  It is all
dependent on the query.

For example: Another query might return 10 ?s.  And within the 10 ?s, I
might need to change the 7th "?".

Does that make sense? 

Peter

-----Original Message-----
From: sanfrancisco-pm-bounces+peter.loo=source.wolterskluwer.com at pm.org
[mailto:sanfrancisco-pm-bounces+peter.loo=source.wolterskluwer.com at pm.or
g] On Behalf Of David Fetter
Sent: Wednesday, June 28, 2006 10:01 AM
To: San Francisco Perl Mongers User Group
Subject: Re: [sf-perl] Quick question on regular expression and
substitution

On Wed, Jun 28, 2006 at 09:19:15AM -0700, Loo, Peter # PHX wrote:
> Hi All,
>  
> Would some one know of a one liner that would replace the third 
> occurrence of a substring within a string?  For example:
>  
> $string = "?, ?, ?, ?";
>  
> I want to replace the third occurrence of "?" with "to_date(?, 
> 'YYYY-MM-DD HH24:MI:SS')".
>  
> Thanks in advance.
>  
> Peter

Peter,

Given the high wackiness of regexes, I'd do something like:

$old = '(?, ?, ?, ?)'; # So you're covered on just exactly which clause.
$new = q{?, ?, to_date(?, 'YYYY-MM-DD HH24:MI:SS'), ?'}; $query =~
s/$old/$new/;

I know it's brute force, but the code is easy to understand later. :)

Cheers,
D
--
David Fetter <david at fetter.org> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

Remember to vote!
_______________________________________________
SanFrancisco-pm mailing list
SanFrancisco-pm at pm.org
http://mail.pm.org/mailman/listinfo/sanfrancisco-pm


This E-mail message is for the sole use of the intended recipient(s) and
may contain confidential and privileged information.  Any unauthorized
review, use, disclosure or distribution is prohibited.  If you are not
the intended recipient, please contact the sender by reply E-mail, and
destroy all copies of the original message.
_______________________________________________
SanFrancisco-pm mailing list
SanFrancisco-pm at pm.org
http://mail.pm.org/mailman/listinfo/sanfrancisco-pm


"MMS <safeway.com>" made the following annotations.
------------------------------------------------------------------------------
Warning: 
All e-mail sent to this address will be received by the Safeway corporate e-mail system, and is subject to archival and review by someone other than the recipient.  This e-mail may contain information proprietary to Safeway and is intended only for the use of the intended recipient(s).  If the reader of this message is not the intended recipient(s), you are notified that you have received this message in error and that any review, dissemination, distribution or copying of this message is strictly prohibited.  If you have received this message in error, please notify the sender immediately. 
  
==============================================================================



More information about the SanFrancisco-pm mailing list