From: Peng Yu on 10 Jul 2010 19:48 Suppose I have a string $x='\t\n', I want to convert it to $y="\t\n". I also want to convert $y back to $x. I have googled. But I haven''t any related function, maybe because I didn't use the right search keywords. Would you please let me know what functions I can use to do the conversions?
From: Ben Morrow on 10 Jul 2010 20:22 Quoth Peng Yu <pengyu.ut(a)gmail.com>: > Suppose I have a string $x='\t\n', I want to convert it to $y="\t\n". > I also want to convert $y back to $x. I have googled. But I haven''t > any related function, maybe because I didn't use the right search > keywords. Would you please let me know what functions I can use to do > the conversions? String::Escape, Encode::Escape. Ben
From: Tad McClellan on 11 Jul 2010 00:55 Peng Yu <pengyu.ut(a)gmail.com> wrote: > Suppose I have a string $x='\t\n', I want to convert it to $y="\t\n". -------------------- #!/usr/bin/perl use warnings; use strict; $_ = q($x='\t\n'); tr/x'/y"/; print "$_\n"; -------------------- -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site.
From: Peter J. Holzer on 11 Jul 2010 05:14 On 2010-07-11 04:55, Tad McClellan <tadmc(a)seesig.invalid> wrote: > Peng Yu <pengyu.ut(a)gmail.com> wrote: >> Suppose I have a string $x='\t\n', I want to convert it to $y="\t\n". > > -------------------- > #!/usr/bin/perl > use warnings; > use strict; > > $_ = q($x='\t\n'); > tr/x'/y"/; > print "$_\n"; > -------------------- From the posting guidelines: | Speak Perl rather than English, when possible | Perl is much more precise than natural language. Saying it in Perl | instead will avoid misunderstanding your question or problem. | | Do not say: I have variable with "foo\tbar" in it. | | Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar', | or I have $var = <DATA> (and show the data line). I think Yu was folling your advice here. hp
From: sln on 11 Jul 2010 12:53 On Sat, 10 Jul 2010 23:55:55 -0500, Tad McClellan <tadmc(a)seesig.invalid> wrote: >Peng Yu <pengyu.ut(a)gmail.com> wrote: > >> Suppose I have a string $x='\t\n', I want to convert it to $y="\t\n". > >-------------------- >#!/usr/bin/perl >use warnings; >use strict; > >$_ = q($x='\t\n'); >tr/x'/y"/; >print "$_\n"; >-------------------- He has a string, it has a known value, its a constant. Any conversion can't be treated programatically if the new value is known and constant. Therefore, transliterate is overkill, conceptually wrong, and slow. The only answer is: $string = q($x='\t\n'); $string = q($y="\t\n"); -sln
|
Next
|
Last
Pages: 1 2 Prev: FAQ 8.45 How do I install a module from CPAN? Next: Perl script permission question |