Forum Moderators: coopster & phranque

Message Too Old, No Replies

Form Submission - Edit Raw Database

edit flat text database

         

Pstrom

4:20 pm on Jun 26, 2005 (gmt 0)

10+ Year Member



NEW TO PERL / PROGRAMMING - NEED HELP URGENT!
ARE WORKING ON A PERL-SCRIPT TO EDIT A "MEMBERS DATABASE" (RAW):

#!/usr/bin/perl
use CGI qw(:all);
print "Content-type: text/html\n\n";
open ($inf, 'data/members.dat');
@data = <$inf>; close ($inf);

print <<END_HTML;
<html><head><title>Edit Database</title></head><body>
<form name="form1" method="post" action="output.pl">
<textarea name="editDB" wrap="off" style="font-family: Verdana, Arial, Helvetica,
sans-serif; font-size: 11px; color: #000000; width:800px; height:500px">@data</textarea>
<input type="hidden" name="password" value="dvy820ppK">
<p>
<a href="javascript:document.forms.form1.submit()">Save Changes</a>
</form>
</body></html>
END_HTML

THIS DISPLAYS IN THE TEXTBOX: (NOTE, "~" indicates a tab-space)
Jack¦j_smith@gibnet.gi¦dsJz6adewPDOs¦03¦March¦19... aso
~Rebecca¦rebecca45689@hotmail.com¦I4MS2Cd2er7Aka... aso
~Neo¦neo11712@hotmail.com¦eXd7PSeYiCb8s¦11¦April... aso
~next line and so on...

PROBLEM IS, I WANT IT LIKE THIS:
Jack¦j_smith@gibnet.gi¦dsJz6adewPDOs¦03¦March¦19... aso
Rebecca¦rebecca45689@hotmail.com¦I4MS2Cd2er7Ak¦1... aso
Neo¦neo11712@hotmail.com¦eXd7PSeYiCb8s¦11¦April¦... aso
next line and so on...

---------------------------------------------
OUTPUT.PL

#!/usr/bin/perl
use CGI qw(:all);
print "Content-type: text/html\n\n";
$check = 'dvy820ppK';
@data = param('editDB');
$ecurity = param('password');
if ($ecurity eq $check) {open ($inf,'>data/members.dat')} else {exit}
print $inf "@data";

FURTHER PROBLEM, THIS WILL MAKE THE DATABASE TO LOOK LIKE THIS: (NOTE, "~" indicates a tab-space)

Jack¦j_smith@gibnet.gi¦dsJz6adewPDOs¦03¦March¦1... aso

~Rebecca¦rebecca45689@hotmail.com¦I4MS2Cd2er7Ak... aso

~Neo¦neo11712@hotmail.com¦exd7pseyicb8s¦11¦apri... Aso

~next line and so on...

PROBLEM IS, I NEED IT LIKE THIS TO WORK: (all left margin)
Jack¦j_smith@gibnet.gi¦dsJz6adewPDOs¦03¦March¦1... aso
Rebecca¦rebecca45689@hotmail.com¦I4MS2Cd2er7Aka... aso
Neo¦neo11712@hotmail.com¦eXd7PSeYiCb8s¦11¦April... aso
next line and so on...

----------------------------------------------------------------

ANYONE PLEASE... ANY IDEAS HOW TO SORT THIS PROBLEM?
SNIP OF JAVASCRIPT?
WRITE SCRIPT DIFFERENT?
STOP "SWABBLING" WITH PERL AND GO FISHING?
WHATEVER?
HELP!
Pstrom =(

Moby_Dim

4:36 pm on Jun 26, 2005 (gmt 0)

10+ Year Member



try to insert after the line :
@data = <$inf>; close ($inf);

this line :
for(@data) {$_=~s/^\s+//}

jatar_k

4:37 pm on Jun 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



and Welcome to WebmasterWorld Pstrom

Moby_Dim

4:42 pm on Jun 26, 2005 (gmt 0)

10+ Year Member



yeah, sorry, Pstrom - welcome, of course :).
(Pity i can't go fishing now :((( )

Pstrom

7:41 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



Yeah tried

for(@data) {$_=~s/^\s+//}

and

foreach $data(@data){
chomp $data;
print INF, $data;
}

no luck so far, I'll be going fishing now...

lexipixel

8:54 pm on Jun 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I see you used javascipt for the submit button... but I don't see the JS in the document to handle it.

Why not just use:

<INPUT TYPE="SUBMIT" VALUE="SAVE CHANGES">

instead of:

<a href="javascript:document.forms.form1.submit()">Save Changes</a>

Moby_Dim

9:09 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



Each your record ends with \n and tab then.

use :

for(@data) {
$_=~s/\s+$//;# cut all to be sure ;)
$_ .= "\n" # add line again
}

or just :

for(@data) {$_=~s/\s+$/\n/}

SHOULD WORK! No more variants! lol

lexipixel

5:39 am on Jun 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you wanting to actually edit the database (manually) or do you just want to convert the entire tab delimted file to another format like newline delimeted?

I can't tell if you want to also edit data within fields of individual records -OR- just have script go through entire (text) "database", reformat lines and write new version of file back out.