Mr. Shawn H. Corey wrote:
> On Mon, 2008-08-11 at 23:30 +0100, Rob Dixon wrote:
>> Mr. Shawn H. Corey wrote:
>>> On Mon, 2008-08-11 at 14:02 -0700, Saya wrote:
>>>>
>>>> I have the following issue:
>>>>
>>>> my $s = "/metadata-files/test-desc.txt,/metadata-files/birthday.txt,/
>>>> web-media/images/bday-after-help.jpg,javascript:popUp('/pop-ups/
>>>> birthday/main.html','bday-pics',785,460);"
>>>>
>>>> Now I want $s to be like: "/metadata-files/test-desc.txt,/metadata-
>>>> files/birthday.txt,/web-media/images/bday-after-help.jpg,/pop-ups/
>>>> birthday/main.html"
>>>>
>>>> I have been working with:
>>>>
>>>> $s =~ s/javascript:popup\('(.*)',(.*)/$1/gi;
>>>
>>> $s =~ s/javascript:popup\('([^']*)',(.*)/$1/gi;
>>
>> There's no reason to capture $2 and not use it.
>>
>> The global substitution is also unlikely to be correct.
> 
> You are making too many assumptions.  The OP only posted one line of
> code.  That does not mean that $2 is not used in the next, in which case
> it should be captured.  And the OP only posted one example.  The real
> data may have more than one match.
> 
> Isn't one of the guidelines for this list is to prune code that has no
> bearing on the problem?
> 
> Don't assume that only what is posted is the whole story.

What is posted cannot possibly be the whole story, and I qualified my answer in
my response. I consider it extremely unlikely that the string

  q~'bday-pics',785,460);~

in $2 is wanted later in the program because I cannot conceive of a likely use
of the /last/ such capture in conjunction with a global substitution. If you are
contending that we cannot assume anything at all about the unseen part of the
program then that precludes almost any useful response altogether.

I believe we should make our best guess about the likely context of the question
and declare any tentative assumptions. If you think the second capture in the
regex and the /g flag on the substitution were probably necessary then I
disagree completely. If you agree with me that they were probably unnecessary
but stuck them in there anyway without comment then I also disagree with you.

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to