2

I have a program in perl that is passed a string from the console. If I pass the string \r\n from the console, it does as it is supposed to and literally stores \r\n into the console arguments as it was created like so:

my $str = '\r\n';

How can I make $str into a CRLF? For example; how can I make

my $str = '\r\n';

into

my $str = "\r\n"; #<--- perl converts \r\n into a carriage return & line feed.  

How can I force perl to convert the string passed from the console into CRLF?

If I am not being clear enough, let me show an example:

my ($arg1, $arg2) = @ARGV;
print $arg1 . $arg2;

Assuming $arg1 was passed 'Hello\r\n' and $arg2 was passed 'World!' it will print Hello\r\nWorld! when I want it to print Hello(newline)World!

0

1 Answer 1

8

You can use the unbackslash function from String::Escape to do this:

use String::Escape qw( unbackslash );

my $str = 'Hello\r\nWorld\r\n';

print unbackslash($str);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.