469,356 Members | 1,893 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Write to File question

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. :)
Jul 19 '05 #1
8 6119
von wrote:
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

Jul 19 '05 #2
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ürgen Exner" <ju******@hotmail.com> wrote in message
news:qAfQd.18798$uc.16755@trnddc05...
von wrote:
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

Jul 19 '05 #3
[Top-posting fixed, please don't do that]
von wrote:
"Jürgen Exner" <ju******@hotmail.com> wrote in message
news:qAfQd.18798$uc.16755@trnddc05...
von wrote:
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?

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
Jul 19 '05 #4
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.

:)

Jul 19 '05 #5
In article <1b********************@comcast.com>, von <vo*@vonvon.com>
wrote:
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.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 19 '05 #6
von wrote:
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
Jul 19 '05 #7
von
Jim Gibson wrote:

(snip)

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

Thanks Jim :)
Jul 19 '05 #8

"von" <vo*@vonvon.com> wrote in message
news:1b********************@comcast.com...
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
Jul 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by burdeen | last post: by
5 posts views Thread by Arvind P Rangan | last post: by
2 posts views Thread by key9 | last post: by
14 posts views Thread by Frank | last post: by
3 posts views Thread by golden | last post: by
20 posts views Thread by cscorley | last post: by
3 posts views Thread by Ben Keshet | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.