Sorry about the syntax errors ... Yes, just want to replace all newline 
characters with a space and since tr does not have g (global) 'option' I was 
thinking that s/\n/ /g is actually better. Or does tr do a global translate by 
default?
 
Thanks
--- On Mon, 8/3/10, John W. Krahn <jwkr...@shaw.ca> wrote:


From: John W. Krahn <jwkr...@shaw.ca>
Subject: Re: tr// versus s///g
To: "Perl Beginners" <beginners@perl.org>
Date: Monday, 8 March, 2010, 9:50


Tony Esposito wrote:
> Does tr/'\n'/' '/

Replace every ' with ' and every "\n" with " " and every ' with '. Should 
probably just be tr/\n/ /.


> do the same as tr/'\n'/' '/g?

I assume you mean s/'\n'/' '/g because /g is not a valid option for tr///.  
That will replace the string "'\n'" with the string "' '" globally but I assume 
you meant s/\n/ /g.


>  ( replace newline with space )
> If so, is one preferred over the other?

tr/// is usually more efficient (faster) than s///g.  Unless you really meant 
to use the string "'\n'" because tr/// cannot do strings, just characters.




John
-- The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

-- To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/





      

Reply via email to