repr() for Perl?

Discussion in 'Python' started by skip@pobox.com, Apr 22, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Mirco Wahab Guest

    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
     
    Mirco Wahab, Apr 22, 2006
    #2
    1. Advertising

  3. Guest


    >> 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, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rasmus Fogh

    multiline repr (code generation)

    Rasmus Fogh, Sep 3, 2003, in forum: Python
    Replies:
    0
    Views:
    374
    Rasmus Fogh
    Sep 3, 2003
  2. David C. Fox

    avoiding recursion in repr?

    David C. Fox, Nov 19, 2003, in forum: Python
    Replies:
    2
    Views:
    372
    David C. Fox
    Dec 4, 2003
  3. tcronj

    str() or repr()

    tcronj, Feb 12, 2004, in forum: Python
    Replies:
    0
    Views:
    376
    tcronj
    Feb 12, 2004
  4. Nikolai Kirsebom

    print / str / repr

    Nikolai Kirsebom, May 18, 2004, in forum: Python
    Replies:
    1
    Views:
    360
    vincent wehren
    May 18, 2004
  5. Edward C. Jones

    Triple quoted repr

    Edward C. Jones, Jun 3, 2004, in forum: Python
    Replies:
    1
    Views:
    313
    Terry Reedy
    Jun 3, 2004
Loading...

Share This Page