Reading from a file
Hi ppl,
Just a *hopefully quick one*
I am new to writing perl and have created
a flat text file to store some variables in
What I am unsure of is how to check on some
information once it's stored.
e.g. name & username stored in users.txt
I want the user to login - the script checks
the name & username and if correct allows
the user to edit info which will be saved
to another file.
I've listed below the way i've saved the
information - just need to know how to
get it back out:
#!/usr/bin/perl
#
print "Content-type: text/html\n\n";
$time= localtime();
$ipaddress = $ENV{'REMOTE_ADDR'};
$test="test.txt";
$maiden="this is a test";
open(file,">>$test");
print file "$time,";
print file "$ipaddress,";
print file "$maiden\n";
close(file);
Any help would be greatly appreciated -
as my grey hairs are starting to show all
of a sudden
Regards
Steve
Rob Pengelly posted this at 02:38 — 7th June 2000.
They have: 850 posts
Joined: Jul 1999
Not 100% sure what you are asking, but I shall try.
There are a few ways you can read data from the file.
The first way is to reading each line 1 at a time, and place each line as an element into an @array.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
myriad posted this at 07:51 — 7th June 2000.
They have: 88 posts
Joined: Mar 1999
Thanks for that - however
Now that i've got the information in an
array how do I compare it with what the
customer has just inputed to see if the
information is the same and let the
customer continue?
many thanks for your help
Regards
Steve
Justin S posted this at 14:23 — 7th June 2000.
They have: 2,076 posts
Joined: Jun 1999
Ok, lets say you have used the array method. Let's also say that you have an HTML page with a field named 'maiden' which is the field you compare to the file. Here's the code... NOTE: I've used the array method so it can be used if there is more then one line you need to compare.
Justin Stayton - [email] [icq]
Rob Pengelly posted this at 19:40 — 7th June 2000.
They have: 850 posts
Joined: Jul 1999
First parse the inputted username/password. For this example, lets say that on each line in the file, things are stored as
username,password,other,data
($u and $p are inputed variables from the form)
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
myriad posted this at 00:04 — 8th June 2000.
They have: 88 posts
Joined: Mar 1999
Cheers you guys!
Many thanks for all your help -
much appreciated.
Just one *little* question left -
Is there an easier way of making
a field required without having to put
if/elseif statements?
Many thanks again.
Steve
Justin S posted this at 01:51 — 8th June 2000.
They have: 2,076 posts
Joined: Jun 1999
No, not using perl. You could through a JavaScript though. The 'if' and 'elsif' statements aren't hard...
------------------
Critiquing over 1000 sites on the Internet today...
Justin Stayton - [email] [icq]
myriad posted this at 14:32 — 8th June 2000.
They have: 88 posts
Joined: Mar 1999
could you check a number of variables
at once to check whether or not information
has been inputed?
e.g. I have a form with several input
boxes named name, email, phone etc.
I want them all to be required so instead
of checking them all individually to see
if there is an input could you do something
like:
if $name=""
elseif $email=""
elseif $phone=""
Sorry You've not entered details
else
continue to next part
I know the above is not correct - am trying
to explain(badly ) what I mean -
new to all this Perl !
Thanks for your continued support
Regards
Steve
richjb posted this at 15:05 — 8th June 2000.
They have: 193 posts
Joined: Feb 2000
The following code should check to make sure that all fields ($name, $email, $pass) were submitted:
[email protected]
Everyone here has a website. It's just that not all are worth posting (Mine! ).
myriad posted this at 19:05 — 10th June 2000.
They have: 88 posts
Joined: Mar 1999
Sorry I haven't replied earlier but just
wanted to say a big thanks to you guys
for the help - much appreciated.
Regards
Steve
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.