Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: OT: Perl and Javascript - escaping newlines

by PodMaster (Abbot)
on Feb 26, 2006 at 09:20 UTC ( [id://532855]=note: print w/replies, xml ) Need Help??


in reply to Re: OT: Perl and Javascript - escaping newlines
in thread OT: Perl and Javascript - escaping newlines

use Data::JavaScript; my @array = ( 1, 2, "f\no\no\n\bar" ); print $_,$/ for jsdump( my_array => \@array); __DATA__ var my_array = new Array; my_array[0] = 1; my_array[1] = 2; my_array[2] = 'f\012o\012o\012\010ar';
This confirms it for me
<a href="javascript:alert('f\012o\012o\012\010ar');"> alert('f\012o\012o\012\010ar') </a>

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re^3: OT: Perl and Javascript - escaping newlines
by ikegami (Patriarch) on Feb 27, 2006 at 15:59 UTC
    In that case,
    my $string = ... from db ...; my $jscode = $string; $jscode =~ s/(\W)/ sprintf('\\0%o', ord($1)) /ge; $jscode = qq{"$jscode"};
    would also work.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://532855]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-03-28 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found