Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Write to File question

Reply
Thread Tools

Write to File question

 
 
von
Guest
Posts: n/a
 
      02-15-2005
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.


 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      02-15-2005
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



 
Reply With Quote
 
 
 
 
von
Guest
Posts: n/a
 
      02-15-2005
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" <(E-Mail Removed)> 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
>
>
>



 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      02-15-2005
[Top-posting fixed, please don't do that]
von wrote:
> "Jürgen Exner" <(E-Mail Removed)> 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


 
Reply With Quote
 
von
Guest
Posts: n/a
 
      02-15-2005
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.





 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      02-15-2005
In article <(E-Mail Removed)>, von <(E-Mail Removed)>
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 =---
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      02-16-2005
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


 
Reply With Quote
 
von
Guest
Posts: n/a
 
      02-16-2005
Jim Gibson wrote:
>
> (snip)
>
> FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
>



Thanks Jim


 
Reply With Quote
 
Matt Mitchell
Guest
Posts: n/a
 
      02-17-2005

"von" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Program to open a file in binary, skip X bytes and write the rest ofthe file to a new file scad C++ 4 05-28-2009 08:47 AM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net 2 07-29-2008 09:50 AM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net Building Controls 0 07-29-2008 01:37 AM
is better to open, write, close file than open, write, append, close? Iulian Ilea Javascript 1 12-21-2006 04:32 PM
How to use Response.write to write to a specific area on a aspx pa =?Utf-8?B?QWJlbCBDaGFu?= ASP .Net 6 05-03-2006 10:16 PM



Advertisments