On Fri, Jan 16, 2004 at 03:38:40PM -0600 James Edward Gray II wrote:
> I have a problem I just cant seem to get my head around, so any help is
> appreciated.
>
> I have a string. It could contain anything a Perl string can contain.
> I have to print this string to a file and later bring it back in
> exactly as it was. However, because of the file format, the string in
> the file may not contain \n characters. That's the only difference
> between the two representations of this string.
>
> Okay, obviously I need to replace all \n characters. Let's say I want
> to follow Perl's example and use a literal \ followed by a literal n.
> Then I would also need to escape \ characters. Okay, again we'll use
> Perl's \ and another \. Does that cover everything if \n is the only
> illegal character in my file format? I believe, so, but please correct
> me if I'm wrong.
Maybe B::perlstring() will do what you need:
[EMAIL PROTECTED]:~$ perl -lMB=perlstring -e '$var = "\n\r\f"; print perlstring( "$var
bla\"\\ \n" )'
"\n\r\f bla\"\\ \n"
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>