|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
I am making a script, were i need to keep a database (just flat file), and i can add to it, and get stuff from it, but how do i get a specific line from it, edit the line, and put it right back over the old line (it's for the EDIT function)
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
The easiest way is to read the lines of the file into an array, replace the desired array element, then write the array back to the file. If the lines in the file are all fixed length, you could use the seek function to read and write a specific line, without having to read and write the whole file. If you have variable length lines, and you don't want to read the entire file into memory, you can use the following method: - Copy the file, line by line, to a temporary file.
- For the line you want to modify, write the modified line, instead of the original line.
- Rename the temporary file to the original file.
|
|
|
|
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
|
P.I.T.A. / Programmer
Joined: Sep 2000
Posts: 755 |
Yup, dave's explanation hits it. There is no really good way to go to one line and edit it, in a random line length file.
"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
one last question. How do i get the info from a form, that is made inside the script? like i can make an external html file, with the form, and do the CGI function to get the data, easy, but how do i get the data from a form that is built into my script?
|
|
|
|
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
|
P.I.T.A. / Programmer
Joined: Sep 2000
Posts: 755 |
I have no idea what you are asking. Can you please explain a little better?
--mark
"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
yeah, something like that, i never knew it was so involved. heh, if you cant tell, im new to perl well, one last question and im set. in my script, i need it to open a file, and append to it, EZ, i know, but i cant seem to understand how to do it. (i alrady have the like i want to append joined and everything, just need to append it.) but the book i have, really doesn't tell you how to do it...so im confused.
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
|
|
|
|
Joined: Feb 2000
Posts: 4,625
Member
|
Member
Joined: Feb 2000
Posts: 4,625 |
What kinda names are those for fish, Dave?
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
omg, so ez, i wish the book was clearer on that.
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
Just to let you know guys, that it works PERFECT!!!
EXECPT, how can i make it automaticly redirect you to the main page after you get done with the script?
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
spoke too soon it works, but it always displays a server misconfiguration message, anyone know why? hes the page its comming from (try putting info in, it should give you a nice looking error page) and here is the script... [edit]uh...code doesn't seem to work...oh well #!/usr/bin/perl -w #------------------------------------------------------------------------------# # # # Script name: Match Scheduler # # Discription: Refs register game between two teams # # Last updated: 11/22/01 # # # #------------------------------------------------------------------------------# #--------- # Password to add a match #--------- $pw = 'le3t'; #---------- # Get form info #---------- use CGI qw(:standard); $ref = param("name"); $f_pw = param("pw"); $team1 = param("team1"); $team2 = param("team2"); $hour = param("hour"); $min = param("min"); $amp = param("amp"); #--------- # Check the ref and password #--------- open(REFS, " while ( { if (!(/^$ref/) || $ref eq '') { $message = 'Sorry, you must be a ref to schedule a match, if you are, make sure you typed in your name correctly'; &message; } } close(REFS);
if ($f_pw ne $pw) { $message = 'Password is incorrect, please try again'; &message; } else { &add; }
sub add { $match = join('|=|', $team1, $team2, $hour, $min, $amp, $ref); open(MATCHES, ">>matches.txt") or die "Cannot open Match file for appending: $!"; print MATCHES "$match n"; close(MATHCES); &message = "Match succesfully added, thanks $ref"; &message; }
sub message { print "Content-type: text/htmlnn"; print<
..:: Infantry Flagging League ::..
..:: Copyright :: Privacy Policy ::.. |
HTML }
[ 11-22-2001: Message edited by: adam ]
[ 11-22-2001: Message edited by: Mark Badolato ]
|
|
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
|
P.I.T.A. / Programmer
Joined: Sep 2000
Posts: 755 |
"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
|
|
|
|
Joined: Mar 2001
Posts: 7,394
Admin / Code Breaker
|
Admin / Code Breaker
Joined: Mar 2001
Posts: 7,394 |
Mark, actually it's a bug in the UBB...
> => >, so it takes the ";" from > and adds it to the ) of the WHILE (), and makes it > (notice the > doesn't have ";" in the end, and the while doesn't have ')')
ex: foreach (
[ 11-23-2001: Message edited by: LK ]
|
|
|
|
Joined: Mar 2001
Posts: 7,394
Admin / Code Breaker
|
Admin / Code Breaker
Joined: Mar 2001
Posts: 7,394 |
BTW Adam,
1. Remove the space before 'HTML' in the end. 2. " close(MATHCES);" or something like that -> typo, should be MATCHES.
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
thanks, can anyone tell my why my [code] thingys didn't work?
|
|
|
|
Joined: Mar 2001
Posts: 7,394
Admin / Code Breaker
|
Admin / Code Breaker
Joined: Mar 2001
Posts: 7,394 |
I think Mark removed it since it caused problems with the look. (since it doesn't wrap)
|
|
|
|
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
|
P.I.T.A. / Programmer
Joined: Sep 2000
Posts: 755 |
Yup. You had had the wrong slash on the code CODE so I fixed it and that caused the wrap to be screwy so I removed it all together
"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
please delete this
[ 11-23-2001: Message edited by: Dave_L ]
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
I don't think this loop does what you want: Try something like this (untested code): [ 11-23-2001: Message edited by: Dave_L ]
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
yeah, it didn't, thanks can anyone tell me how you would split pages up? Like only 20 entries a page, or only entrys that start with A on one page?
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
split pages up
I don't understand what you mean. Please explain in more detail what you want to do.
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
like with ubb, it will only show topics from like 10 days ago on one page, I want to do something of the same nature, only show 20 entries on one page, or show just the entrys that start with "A" on one page, get me?
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
Ok, I see. I assume your "entries" are all in one file? Read through the file, pick out the entries you want to display (based on whatever criteria you want to use), and display only those entries. If you want to allow users to "page through" all the entries, it gets more complicated, since you need to keep track of what "page" the user is on. CGI is a "stateless" protocol, so you have to do this yourself. One solution is to use a hidden form field to store the current page number or item number. Hope this helps.
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
yes it does, thanks You are a BIG help Dave!
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
Hmmm...I must be stupid or something, but i cant figure this out. go here ( http://ifl.nmebase.com), look at the upcomming matches section, for SOME reason its just showing like the frist letter. Okay, my script opens the file, for reading, and takes a line (like this) then my script takes the file, splits it by |=| and saves it into vaiables to display, but like i said, its only displaying the frist letter of the variable, can anyone tell me why? here is the block of code being used. [ 11-27-2001 04:58 PM: Message edited by: adam ]
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
Joined: Aug 2000
Posts: 335 |
should be The pipe is a metacharacter, so it has to be escaped when used in a 'split' pattern: In this 'if' predicate, '=' should be '==' to do a numeric comparison, or 'eq' to do a string comparison. If $amp will always be a number, I would do a numeric comparison. [ 11-28-2001 06:08 PM: Message edited by: Dave_L ]
|
|
|
|
Joined: Jul 2001
Posts: 108
Member
|
Member
Joined: Jul 2001
Posts: 108 |
thanks Dave, you should be the moderator of this forum
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 808
Joined: July 2001
|
|
Forums63
Topics37,573
Posts293,925
Members13,849
|
Most Online5,166 Sep 15th, 2019
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|
|
|
|