haast
asked on
Remove carrige return line feed from a string
I have a $variable received from a HTML textarea form. EG:
This
is
a
test
I want to remove the newlines (carrige return line feeds)from it, so that it looks like:
This is a test
I have tried $variable =~ tr/\n/ /;
BUT IT DOES NOT SEEM TO WORK ????????
This
is
a
test
I want to remove the newlines (carrige return line feeds)from it, so that it looks like:
This is a test
I have tried $variable =~ tr/\n/ /;
BUT IT DOES NOT SEEM TO WORK ????????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Global flag is not needed as the sample data only conains one CR per line.
\n is the new line delimiter for your operating system, meaning LF for Unix or CR/LF for Windows/DOS, there should be no need to explicitly remove carriage returns.
jhurst, the normal etiquitte here is to submit answers as comments and let the questioner decide which ones to accept.
\n is the new line delimiter for your operating system, meaning LF for Unix or CR/LF for Windows/DOS, there should be no need to explicitly remove carriage returns.
jhurst, the normal etiquitte here is to submit answers as comments and let the questioner decide which ones to accept.
Why do you say that $variable =~ tr/\n/ /; does not seem to work?
ASKER
teraplane thank you for your suggestion (it did not solve the problem), jhurst is 100% correct the g flag is ESSENTIAL and also besides the =~ s/\n// the =~ s/\r// is ESSENTIAL too.
And I concur with the comment on etiquitte, however, I do understand enthusiasm, so let us all learn from this.
Best Regards,
haast.
PS: ozo you are not forgotten as a potential helper as well.
Thank you ALL.
And I concur with the comment on etiquitte, however, I do understand enthusiasm, so let us all learn from this.
Best Regards,
haast.
PS: ozo you are not forgotten as a potential helper as well.
Thank you ALL.
$variable =~ s/\n//;