How to write a script that takes input from the screen and writes a number to a text file?

Discussion in 'Perl Misc' started by Poppy Gerard, Dec 24, 2003.

  1. Poppy Gerard

    Poppy Gerard Guest

    24/12/03 - am

    Hi there. I am not sure if PERL is the right way to do this - but I
    am trying to generate a simple script that will run at a Website and
    accept a numerical input typed in on the screen, and write the number
    to a simple ASCII text file.

    Does anyone know how one can do this with PERL, or is there a better /
    easier way to generate such a program on-line?

    I would be grateful for any help / advice that people may be able to
    offer.

    With many thanks,
    and Seasons Greetings,


    Poppy Gerard
    Poppy Gerard, Dec 24, 2003
    #1
    1. Advertising

  2. "Poppy Gerard" <> wrote in message
    news:...
    > 24/12/03 - am
    >
    > Hi there. I am not sure if PERL is the right way to do this - but I
    > am trying to generate a simple script that will run at a Website and
    > accept a numerical input typed in on the screen, and write the number
    > to a simple ASCII text file.
    >
    > Does anyone know how one can do this with PERL, or is there a better /
    > easier way to generate such a program on-line?
    >
    > I would be grateful for any help / advice that people may be able to
    > offer.


    I am sorry, but it really sounds like your best option is to get someone to
    do it for you , because your question seems to indicate that you have no
    idea what you are talking about.

    That said, assuming I am decoding your question correctly and you want
    a html form page on the website and a script to process whatever the user
    entered into it and submitted, then yes, Perl is a way to do it.
    You can use the CGI module to interface with the webserver.

    gnari
    Ragnar Hafstað, Dec 24, 2003
    #2
    1. Advertising

  3. Poppy Gerard

    Sara Guest

    (Poppy Gerard) wrote in message news:<>...
    > 24/12/03 - am
    >
    > Hi there. I am not sure if PERL is the right way to do this - but I
    > am trying to generate a simple script that will run at a Website and
    > accept a numerical input typed in on the screen, and write the number
    > to a simple ASCII text file.
    >
    > Does anyone know how one can do this with PERL, or is there a better /
    > easier way to generate such a program on-line?
    >
    > I would be grateful for any help / advice that people may be able to
    > offer.
    >
    > With many thanks,
    > and Seasons Greetings,
    >
    >
    > Poppy Gerard
    >



    Hello Poppy:

    your "screen" is generally an output device, unless you have a
    touchscreen? Do you mean the keyboard?

    my $x = <STDIN>;

    will snag a line typed on your keyboard if that's what you're after.

    So something like

    # get the input and test it
    $_ = <STDIN>;
    chomp;
    die "hey pardner this aint no number!!\n\n" unless /^\d+$/;

    # output it to a file
    die "Tarnation this dad-blamed file wont open!!\n\n" unless open F,
    ">myOutputFile";
    print F;
    close F;

    print "wow I sure like CLPM\n\n";

    g
    Sara, Dec 24, 2003
    #3
  4. Poppy Gerard <> wrote:

    > I am not sure if PERL



    The name of the language is "Perl".

    The name of the interpreter is "perl".

    It is not an acronym.

    perldoc -q difference


    > is the right way to do this - but I
    > am trying to generate a simple script that will run at a Website and



    You want to write a "CGI program".

    You can write a CGI program in just about any programming language
    that you choose.

    Many many people do happen to choose to use Perl for their CGI programs.


    > accept a numerical input typed in on the screen,



    There is no "screen" in a CGI program.

    A CGI program gets it input from the web server[1], and sends its
    output to the web server[2].


    > and write the number
    > to a simple ASCII text file.
    >
    > Does anyone know how one can do this with PERL, or is there a better /
    > easier way to generate such a program on-line?



    People write programs.

    Programs generate programs.

    Their is no general purpose program-generator, you will need to
    _write_ a program. To so that, you will need to learn a programming
    language, perhaps Perl, perhaps anything else you might like.

    If you chose to write that program using Perl, then it might
    look something like this (untested):

    ----------------------------------------------
    #!/usr/bin/perl
    use strict;
    use warnings;
    use CGI qw/:standard/;
    use CGI::Carp;

    open FILE, '>simple_ASCII.txt' or
    carp "could not open 'simple_ASCII.txt' $!";
    print FILE param('the_number_from_the_form'), "\n";
    close FILE or carp "problem closing file $!";

    print "Content-Type: text/plain\n\n";
    print param('the_number_from_the_form'), " has been written to the file\n";
    ----------------------------------------------


    That's it!


    (except a Real CGI Program would need to deal with multitasking and
    do some form of file locking.
    )


    > I would be grateful for any help / advice that people may be able to
    > offer.



    There are a bazillion Perl FAQs about what you want to do, all you need
    are some good search terms:

    perldoc -q CGI
    How can I make my CGI script more efficient?
    Where can I learn about CGI or Web programming in Perl?
    What is the correct form of response from a CGI script?
    My CGI script runs from the command line but not the
    browser. (500 Server Error)
    How can I get better error messages from a CGI program?
    How do I make sure users can't enter values into a form
    that cause my CGI script to do bad things?
    How do I decode a CGI form?

    perldoc -q "\block"
    How can I lock a file?
    Why can't I just open(FH, ">file.lock")?
    I still don't get locking. I just want to increment the
    number in the file. How can I do this?



    See also the Posting Guidelines that are posted here frequently.




    [1] the web server in turn may have gotten the values from a <form>
    filled out in a client program (eg. browser).

    [2] the web server in turn may forward the output to a client program.

    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Dec 24, 2003
    #4
  5. Poppy Gerard

    Poppy Gerard Guest

    Many thanks for all these replies, and for the suggestions. I shall
    check out some of the ideas for FAQs etc and look into this some more.
    Thank you once again. With all good wishes for 2004! :) Kindest
    regards - Poppy G.



    (Tad McClellan) wrote in message news:<>...
    > Poppy Gerard <> wrote:
    >
    > > I am not sure if PERL

    >
    >
    > The name of the language is "Perl".
    >
    > The name of the interpreter is "perl".
    >
    > It is not an acronym.
    >
    > perldoc -q difference
    >
    >
    > > is the right way to do this - but I
    > > am trying to generate a simple script that will run at a Website and

    >
    >
    > You want to write a "CGI program".
    >
    > You can write a CGI program in just about any programming language
    > that you choose.
    >
    > Many many people do happen to choose to use Perl for their CGI programs.
    >
    >
    > > accept a numerical input typed in on the screen,

    >
    >
    > There is no "screen" in a CGI program.
    >
    > A CGI program gets it input from the web server[1], and sends its
    > output to the web server[2].
    >
    >
    > > and write the number
    > > to a simple ASCII text file.
    > >
    > > Does anyone know how one can do this with PERL, or is there a better /
    > > easier way to generate such a program on-line?

    >
    >
    > People write programs.
    >
    > Programs generate programs.
    >
    > Their is no general purpose program-generator, you will need to
    > _write_ a program. To so that, you will need to learn a programming
    > language, perhaps Perl, perhaps anything else you might like.
    >
    > If you chose to write that program using Perl, then it might
    > look something like this (untested):
    >
    > ----------------------------------------------
    > #!/usr/bin/perl
    > use strict;
    > use warnings;
    > use CGI qw/:standard/;
    > use CGI::Carp;
    >
    > open FILE, '>simple_ASCII.txt' or
    > carp "could not open 'simple_ASCII.txt' $!";
    > print FILE param('the_number_from_the_form'), "\n";
    > close FILE or carp "problem closing file $!";
    >
    > print "Content-Type: text/plain\n\n";
    > print param('the_number_from_the_form'), " has been written to the file\n";
    > ----------------------------------------------
    >
    >
    > That's it!
    >
    >
    > (except a Real CGI Program would need to deal with multitasking and
    > do some form of file locking.
    > )
    >
    >
    > > I would be grateful for any help / advice that people may be able to
    > > offer.

    >
    >
    > There are a bazillion Perl FAQs about what you want to do, all you need
    > are some good search terms:
    >
    > perldoc -q CGI
    > How can I make my CGI script more efficient?
    > Where can I learn about CGI or Web programming in Perl?
    > What is the correct form of response from a CGI script?
    > My CGI script runs from the command line but not the
    > browser. (500 Server Error)
    > How can I get better error messages from a CGI program?
    > How do I make sure users can't enter values into a form
    > that cause my CGI script to do bad things?
    > How do I decode a CGI form?
    >
    > perldoc -q "\block"
    > How can I lock a file?
    > Why can't I just open(FH, ">file.lock")?
    > I still don't get locking. I just want to increment the
    > number in the file. How can I do this?
    >
    >
    >
    > See also the Posting Guidelines that are posted here frequently.
    >
    >
    >
    >
    > [1] the web server in turn may have gotten the values from a <form>
    > filled out in a client program (eg. browser).
    >
    > [2] the web server in turn may forward the output to a client program.
    Poppy Gerard, Dec 29, 2003
    #5
    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. Meitham
    Replies:
    3
    Views:
    393
    Meitham
    Nov 1, 2007
  2. owl
    Replies:
    2
    Views:
    876
  3. Paul
    Replies:
    1
    Views:
    110
    Sebastian Hungerecker
    Apr 24, 2007
  4. Benoit Fries
    Replies:
    1
    Views:
    76
    Thomas 'PointedEars' Lahn
    Nov 14, 2003
  5. Replies:
    3
    Views:
    156
    J. Gleixner
    Oct 22, 2007
Loading...

Share This Page