Write to File question

V

von

I am writing data from a Javascript to a text file using a Perl script and
it all works pretty well - except ...

This:

"Here is my data"

becomes:

"Here%20is%20my%20data" when it gets to the text file.


Is there a way to replace the "%20" for a normal space as the Perl script
writes it to file??

Thanks. :)
 
J

Jürgen Exner

von said:
I am writing data from a Javascript to a text file using a Perl

Somewhere you are not telling us something because taking your description
literally it doesn't make any sense.
What are you doing?

jue
 
V

von

I am running a Javascript that generates a piece of data.

I am then sending this data to a text file via a Perl script.

Somewhere along the way the spaces in-between the data are changed to
"%20" - and I would like to change them back to spaces to make it easier to
read.

:)
 
J

Jürgen Exner

[Top-posting fixed, please don't do that]
I am running a Javascript that generates a piece of data.
I am then sending this data to a text file via a Perl script.

Saying the same thing again in the same way doesn't really help
understanding.
Trying to rephrase, please correct me if I missunderstood:
You have a Javascript, that sends data to a Perl script, which in turn
writes the data to a file.

If this is correct then you didn't tell us anything about _HOW_ the data is
transmitted between the JavaScript and the Perl script. And obviously that
is the crucial point.
Somewhere along the way the spaces in-between the data are changed to
"%20" - and I would like to change them back to spaces to make it
easier to read.

But you didn't tell us what the way is.... :-(

jue
 
V

von

Okay - let me start over. :)

I have a Javascript that generates a piece of information that I want
written to a file on my server.

I used this in the Javascript to send it to a Perl Script:
_________________________________
var i=new Image();

i.src="http://www.mydomain.com/cgi-bin/write.pl?" + user;

______________________________________


Then I use the following Perl script (write.pl) to send the data to my text
file:
________________________________
#!/usr/bin/perl

use CGI::Carp qw( fatalsToBrowser );
$isdata= $ENV{QUERY_STRING};

# Set $data_file to the location and name of the file in question.
my $data_file = '/usr/home/mydomain/public_html/data1.txt';

open (DATA, "+>>$data_file") or die "can't open $data_file $!";
print DATA "$isdata";

{
print "$_\n";
}
close (DATA);
__________________________________

My problem is that the data arrives to the text file with '%20' in place of
the spaces.

ie: "This%20is%20the%20data"

I would like the '%20' converted back to spaces.

I have been playing with 'unescape()' but I can't seem to get it to work
(user error I'm sure).

Any help would be appreciated.

:)
 
J

Jim Gibson

von <[email protected]> said:
Okay - let me start over. :)

I have a Javascript that generates a piece of information that I want
written to a file on my server.

I used this in the Javascript to send it to a Perl Script:
_________________________________
var i=new Image();

i.src="http://www.mydomain.com/cgi-bin/write.pl?" + user;

______________________________________


Then I use the following Perl script (write.pl) to send the data to my text
file:
________________________________
#!/usr/bin/perl

use CGI::Carp qw( fatalsToBrowser );
$isdata= $ENV{QUERY_STRING};

# Set $data_file to the location and name of the file in question.
my $data_file = '/usr/home/mydomain/public_html/data1.txt';

open (DATA, "+>>$data_file") or die "can't open $data_file $!";
print DATA "$isdata";

{
print "$_\n";
}
close (DATA);
__________________________________

My problem is that the data arrives to the text file with '%20' in place of
the spaces.

ie: "This%20is%20the%20data"

I would like the '%20' converted back to spaces.

$isdata =~ s/%20/ /g

You can also try the query_string() method of the CGI module, but I
can't tell from the docs whether that decodes the URL encoding or not.

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
 
J

Jürgen Exner

von said:
Okay - let me start over. :)

I have a Javascript that generates a piece of information that I want
written to a file on my server.

I used this in the Javascript to send it to a Perl Script:
_________________________________
var i=new Image();

i.src="http://www.mydomain.com/cgi-bin/write.pl?" + user;

Sorry, can't help you with that. Never used Perl in a CGI environment.

But I heard of some URI::decode or something similar to that on CPAN.

jue
 
M

Matt Mitchell

Then I use the following Perl script (write.pl) to send the data to my
text file:
________________________________
#!/usr/bin/perl

use CGI::Carp qw( fatalsToBrowser );
$isdata= $ENV{QUERY_STRING};
open (DATA, "+>>$data_file") or die "can't open $data_file $!";
print DATA "$isdata";
My problem is that the data arrives to the text file with '%20' in place
of the spaces.

ie: "This%20is%20the%20data"

You can do this kind of thing using your own code, but the best way to do it
is to use the functions provided by the Carp module.

Start with
use CGI;

and have a look at the documentation for it - it's a much better way to do
things than to process STDIN "manually", since someone else has already
written the code you need to do the job. Any beginner's tutorial online
that talks about perl and CGI will tell you what to do.

Matt
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top