On Wed, Oct 22, 2003 at 07:22:24PM +0200, Kevin Pfeiffer wrote:
> In article <[EMAIL PROTECTED]>, Charles K. Clarkson
> wrote:
> 
> > Kevin Pfeiffer <[EMAIL PROTECTED]> wrote:
> > 
> > : Where I am stuck is on the question:
> > : 
> > : Given an @array such as
> > : ("Title of Song", "Artist", "Title", "Another Artist", "etc"),
> > : is there an easy way to strip out the quotation marks.
> > 
> >     s/"//g foreach @array;
> 
> Ahhh, that's so nice. I should have known better and just tried that. I'm
> guessing that in such a format internal quote marks would have to be
> escaped? So I could do:
> 
> s/[^\]"//g...   ?


Kevin, 

I don't think that's what you want.  That will run through your string
and, everywhere that it sees a " it will strip the quote and the
previous character unless the previous character is a \, in which case
it won't do anything.  So, yes, it preserves escaped "s, but it
accidentally nukes other characters.  (Also, you need to escape the
\.)

I think what you want is a negative look-behind:

s/(?<!\\)"//g

Note that this will strip a leading quote as well as an internal one.
Check http://perldoc.com/perl5.8.0/pod/perlre.html for details on
negative (and positive) look-behinds and -aheads.  They are very useful.


--Dks


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to