470,815 Members | 1,287 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

repr() for Perl?

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:

http://wiki.python.org/moin/PerlPhrasebook

but saw nothing along those lines.

Thx,

Skip
Apr 22 '06 #1
2 2586
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
Apr 22 '06 #2
Does Perl have something like Python's repr() function?


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
Apr 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by tcronj | last post: by
1 post views Thread by Edward C. Jones | last post: by
1 post views Thread by Noam Raphael | last post: by
5 posts views Thread by nummertolv | last post: by
9 posts views Thread by Matthew Wilson | last post: by
1 post views Thread by Raymond Hettinger | last post: by
reply views Thread by Terry Reedy | last post: by
2 posts views Thread by Mark Tolonen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.