repr() for Perl?

M

Mirco Wahab

Hi skip
Sorry to ask a Perl question here, but... Does Perl have something like
Python's repr() function? I want to print out a string and have CR print as
\r, LF as \n, etc. I looked in the Perl/Python phrasebook:

Have a look at this:

# -------- cmp_rep.pl ----------- #
#!/usr/bin/perl -w
use String::Escape qw(printable);

# - - - - the perl way - - - - -
$st = "str\ting\n";
print "In Perl:\n", printable($st);

# - - - - the python way - - - -
use Inline Python => <<'PYEND';
st="str\ting\n";
print "\nIn Python:\n", repr(st)
PYEND
# ------------------------------- #

Should give "almost" the same results

Regards

Mirco
 
S

skip

Mirco> Have a look at this:

...

Thanks, I'm getting set up to try it just for the exercise. I went with
John Lee's Data::Dumper suggestion simply because I already had it installed
and have neither String::Escape nor Inline::python installed.

Skip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top