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

P

Poppy Gerard

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
(e-mail address removed)
 
R

Ragnar Hafstað

Poppy Gerard said:
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
 
S

Sara

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
(e-mail address removed)


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
 
T

Tad McClellan

Poppy Gerard said:
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.
 
P

Poppy Gerard

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.



Poppy Gerard said:
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.
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top