Write to File question

Discussion in 'Perl' started by von, Feb 15, 2005.

  1. von

    von Guest

    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. :)
     
    von, Feb 15, 2005
    #1
    1. Advertising

  2. 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
     
    Jürgen Exner, Feb 15, 2005
    #2
    1. Advertising

  3. von

    von Guest

    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" <> 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
    >
    >
    >
     
    von, Feb 15, 2005
    #3
  4. [Top-posting fixed, please don't do that]
    von wrote:
    > "Jürgen Exner" <> 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
     
    Jürgen Exner, Feb 15, 2005
    #4
  5. von

    von Guest

    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.

    :)
     
    von, Feb 15, 2005
    #5
  6. von

    Jim Gibson Guest

    In article <>, 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;
    >
    > ______________________________________
    >
    >
    > 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 =---
     
    Jim Gibson, Feb 15, 2005
    #6
  7. 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
     
    Jürgen Exner, Feb 16, 2005
    #7
  8. von

    von Guest

    Jim Gibson wrote:
    >
    > (snip)
    >
    > FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
    >



    Thanks Jim :)
     
    von, Feb 16, 2005
    #8
  9. "von" <> wrote in message
    news:...

    > 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
     
    Matt Mitchell, Feb 17, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWJlbCBDaGFu?=
    Replies:
    6
    Views:
    9,494
    Rahul
    May 3, 2006
  2. Peter Hansen
    Replies:
    1
    Views:
    405
    Joona I Palaste
    Aug 24, 2003
  3. scad
    Replies:
    4
    Views:
    970
    James Kanze
    May 28, 2009
  4. Iulian Ilea
    Replies:
    1
    Views:
    335
    pcx99
    Dec 21, 2006
  5. Tim Chase
    Replies:
    0
    Views:
    103
    Tim Chase
    Dec 16, 2013
Loading...

Share This Page