473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 2684
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: tcronj | last post by:
Have reasently upgraded to PySQLite 0.5. I now have to "typecast" returned values to the "string expecting" GUI widgets (wxPython). Afrer reading the explanation, I'm still not clearer wich is...
1
by: Edward C. Jones | last post by:
On 2003-09-04, Rasmus Fogh said: > I need a way of writing strings or arbitrary Python code that will > > a) allow the strings to be read again unchanged (like repr) > b) write multiline...
1
by: Noam Raphael | last post by:
Hello, repr(0.1) is '0.10000000000000001', in my Python 2.3. From reading the article "Floating Point Arithmetic: Issues and Limitations", I understand that it's the closest 17-digit decimal...
5
by: nummertolv | last post by:
Hi, My application is receiving strings, representing windows paths, from an external source. When using these paths, by for instance printing them using str() (print path), the backslashes are...
9
by: Matthew Wilson | last post by:
I understand that idea of an object's __repr__ method is to return a string representation that can then be eval()'d back to life, but it seems to me that it doesn't always work. For example it...
0
by: Anthony Baxter | last post by:
SECURITY ADVISORY Buffer overrun in repr() for UCS-4 encoded unicode strings http://www.python.org/news/security/PSF-2006-001/ Advisory ID: PSF-2006-001 Issue Date: October 12, 2006...
1
by: Raymond Hettinger | last post by:
Was looking at PEP 3108, http://www.python.org/dev/peps/pep-3108/ , and saw that the repr module was slated for vaporization. I've only used the module a few times ever. I'm curious if the...
0
by: Terry Reedy | last post by:
Karen Tracey wrote: If answers here do not satisfy, the pydev list would be the place to request that this change be put off until 3.0, when changes that break are more permissible. I do not...
2
by: Mark Tolonen | last post by:
I don't understand the behavior of the interpreter in Python 3.0. I am working at a command prompt in Windows (US English), which has a terminal encoding of cp437. In Python 2.5: Python 2.5...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.