Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Strange print

0 views
Skip to first unread message

Valerij KIR

unread,
Jan 31, 2006, 10:09:35 AM1/31/06
to
Hi all!
I have some text in russian. Then I've print it with puts I saw beatiful
text, but then use p operator text is "\353\317\314\314\305\304\326".
How can I solve problem, because when using iconv the problem is same?

--
Posted via http://www.ruby-forum.com/.


Robert Klemme

unread,
Jan 31, 2006, 10:20:50 AM1/31/06
to
Valerij KIR wrote:
> Hi all!
> I have some text in russian. Then I've print it with puts I saw
> beatiful text, but then use p operator text is
> "\353\317\314\314\305\304\326". How can I solve problem, because when
> using iconv the problem is same?

p uses String#inspect which I believe will always print something that can
be safely interpreted as a Ruby string on 7 bit ASCII. You should use
puts instead of p - p is really rather a debugging / inspection untility
but not meant for normal program output (IMHO).

Kind regards

robert

Gennady Bystritsky

unread,
Jan 31, 2006, 11:00:29 AM1/31/06
to
I am not completely sure, but you can try to play with $KCODE variable
settings. I am sure you know this, put 'p "abc"' is equivalent to 'puts
"abc".inspect' and 'inspect' outputs non-printable characters in escaped
form (like '\n' or '\326').

UPDATE: I just checked that with $KCODE = 'u', p shows "College" in
Russian just like that -- "bea[u]tiful text" ;-).

Gennady.

> -----Original Message-----
> From: list-...@example.com
> [mailto:list-...@example.com] On Behalf Of Valerij KIR
> Sent: Tuesday, January 31, 2006 7:10
> To: ruby-talk ML
> Subject: Strange print
>
> Hi all!
> I have some text in russian. Then I've print it with puts I
> saw beatiful text, but then use p operator text is
> "\353\317\314\314\305\304\326".
> How can I solve problem, because when using iconv the problem is same?
>

Eero Saynatkari

unread,
Jan 31, 2006, 1:41:46 PM1/31/06
to
Valerij Kirjanov wrote:
> Hi all!
> I have some text in russian. Then I've print it with puts I saw beatiful
> text, but then use p operator text is "\353\317\314\314\305\304\326".
> How can I solve problem, because when using iconv the problem is same?

The difference between puts obj and p obj is that the
former uses obj.to_s and the latter obj.inspect. Is
there a specific reason why you need to use p instead
of puts or did I misunderstand you?


E

0 new messages