repr() for Perl?
Mirco Wahab
wahab at chemie.uni-halle.de
Sat Apr 22 08:52:16 EDT 2006
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
More information about the Python-list
mailing list