David Wright
David Wright

Reputation: 435

Removing carriage return from beginning of string in Perl?

I understand how to remove carriage returns from the ends of strings -- but I'm running into an issue in a Perl script of mine where a carriage return is found before the string.

For example, my script searches for strings which start with an exclamation mark, but a line that causes problems in my script is: ^C!

Is there any way to remove this?

Upvotes: 0

Views: 463

Answers (2)

Miguel Prz
Miguel Prz

Reputation: 13792

you could use a regexpr to clean that characters:

$line =~ s/^[^!]//;

Upvotes: 1

daxim
daxim

Reputation: 39158

^C is not the cat -v representation of carriage return, but of ETX, maybe that's the source of your confusion. s/\cC// will remove it.

Check with Devel::Peek::Dump from within Perl or uniquote from outside for other invisible characters.

Upvotes: 2

Related Questions