473,657 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2690
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
1266
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 better to use... str() or repr() example: self.wxTextCtrl.Setvalue( str(val)) ## or repr(val)
1
2386
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 strings as multiline strings instead of escaping > the \n's. > > A repr function that output triple-quoted strings with explicit > (non-escaped) linebreaks would be perfect.
1
1610
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 representation of the binary floating-point number actually stored. However, I don't understand why this should be what repr of floats returns. repr should, if possible, return a string that evaluating it will be == to the original object. But...
5
3098
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 naturally interpreted as escape characters. >>> print "d:\thedir" d: hedir
9
3999
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 doesn't work for instances of the object class: In : eval(repr(object())) ------------------------------------------------------------ File "<string>", line 1 <object object at 0xf233e8>
0
1643
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 Product: Python Versions: 2.2, 2.3, 2.4 prior to 2.4.4, wide unicode (UCS-4) builds only CVE Names: CAN-2006-4980
1
1118
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 community wants it kept around or whether it is considered clutter. The PEP is going to be finalized soon, so if you have issues with it, they should be sent to the PEP author or brought up on the list,...
0
863
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 remember any discussion of this issue. You can also post there via news.gmane.org/g.c.python.devel (the mail to news gateway).
2
2720
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 (r25:51908, Sep 19 2006, 09:52:17) on win 32 Type "help", "copyright", "credits" or "license" for more information. u'\u5000'
0
8413
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7352
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.