Cool it works, thanks alot for your help.

-----Original Message-----
From: James Edward Gray II [mailto:[EMAIL PROTECTED]
Sent: Monday, July 26, 2004 9:04 PM
To: [EMAIL PROTECTED]
Cc: Perl Beginners
Subject: Re: Multiple Parameters


On Jul 26, 2004, at 6:29 PM, <[EMAIL PROTECTED]> wrote:

> Thank you very much for your help, but i have one more question, is 
> this the
> way that regex works or is it something in my code, every time i try 
> to run
> the script to search for a comma and replace it with a new line 
> character
> (\n) it just removes the commas but doesn't replace it with a new line
> character.

What is it replacing them with?  n's?

I'm betting your shell is swallowing the \, turning \n into just n.  If 
that's true, you have to get a \ past the shell first.  On my Unix box, 
both \\n and '\n' work.

Unfortunately, that doesn't solve your problem.  Because then you'll 
replace ,s with a \ followed by an n.  You want \n translated into a 
newline character, as it is in Perl's double quoted strings.

We could search your string for a \ followed by an n and replace it 
with a newline character, but that opens a another can of worms:  What 
if you really wanted to replace with a \ and an n?

Given that, we can eval() your string to get Perl's string behavior.  
That'll do what you want in this case, but may complicate some other 
cases for you, say if you're making a CSV file and want to replace with 
"".

It's all tradeoffs.

Here's a simple change to eval() your string:

s/$search/qq("$replace")/eeg;   # update your search to this

Hope that helps.

James


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




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


Reply via email to