Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: problems editing a flat-file | my input to your effort

by andr321 (Initiate)
on Apr 29, 2008 at 06:20 UTC ( [id://683418]=note: print w/replies, xml ) Need Help??


in reply to problems editing a flat-file

I was searching online for help myself, I found your case. I have trying to work on it. I found out something that is good you can do, if not you will be able to use what I supply to you and you will get your way around.

It is not a solution, but a tool.

Change your file name like this:

my $query =new CGI; # my $guest_file = "/cgi-bin/data/igb-data.ais"; my $guest_file ="andre1.txt"; &print_page_start; if ($query->param()) { if ($query->param('new_name')) { if (&valid_form) { # my $guest_file ="andre1.txt"; eval { open (GUESTS, "+>> $guest_file") or die "Can't open $guest_file: $!"; flock GUESTS, 2; seek GUESTS, 0, 0; my @guests = <GUESTS>; my @new_guests = (); keep it in the same directory till you get everything in order. Your "{" in the sub.... sub print_page_start { print $query->header; print "<HTML>\n<HEAD>\n<TITLE>Modify Records</TITLE>\n"; print "</HEAD>\n<BODY>\n"; print "<H1>Modify Records</H1>\n"; # }
must go away. This is where you have an outpout with no data in the "Modify Records."

Create andre1.txt or any file with your fields names and your delimiter you chose:

Gray Hair |hair@yahoo.com| Wisdom of old man

Try it. It may delete your file when you click submit, but play with it. That is your first bullet to see something on the screem. Let me know what you come up with.

Anre is my name.

I will hear from you in this post.

I have no idea on your retrieve.pl but if it works fine, it should serve well instead of andre1.txt and my output on the screen. Submit destroy it, but you may continue from there. There is a +'; that I put on coment for you too.

I am not a programer in perl, I know nothing,but I love to learn and to be around the learners and the experts.

Here your full code here. copy it and paste it and do : http://127.0.0.1/cgi-bin/data1/data2.pl It should give you a better result.

#!/usr/bin/perl use CGI; my $query =new CGI; # my $guest_file = "/cgi-bin/data/igb-data.ais"; my $guest_file ="andre1.txt"; &print_page_start; if ($query->param()) { if ($query->param('new_name')) { if (&valid_form) { # my $guest_file ="andre1.txt"; eval { open (GUESTS, "+>> $guest_file") or die "Can't open $guest_file: $!"; flock GUESTS, 2; seek GUESTS, 0, 0; my @guests = <GUESTS>; my @new_guests = (); foreach $guest (@guests) { chomp $guest; ($name, $email, $comments) = split ('\|\|'), $guest; if ($name eq $query->param('name') && $email eq $query->param('email') && $comments eq $query->param('comments')) { $name = $query->param('new_name'); $email = $query->param('new_email'); $comments = $query->param('new_comments'); $guest = "$name||$email||$comments"; } local $/ = local $\ = local $, = "vroom"; push @new_guests, $guest; } seek GUESTS, 0,0; truncate GUESTS, 0; print GUESTS @new_guests; close GUESTS; print "<P>Record(s) modified.</P>\n"; # print "<A HREF=\"retrieve.pl\">Retrieve records.</A>\n"; print "<A HREF=\"retrieve.pl\">Retrieve records.</A>\n"; } } else { &print_form; } } else { &print_form; } } else { &print_record_list; } chomp $@; if ($@) { print "ERROR: $@<BR>\n"; } &print_page_end; sub print_page_start { print $query->header; print "<HTML>\n<HEAD>\n<TITLE>Modify Records</TITLE>\n"; print "</HEAD>\n<BODY>\n"; print "<H1>Modify Records</H1>\n"; # } # sub print_form { print "<P>\n<FORM>\n"; if (!$query->param()) { print "Name: <INPUT TYPE=\"text\" NAME=\"new_name\"><BR>\n"; print "Email: <INPUT TYPE=\"text\" NAME=\"new_email\"><BR>\n"; print "Comments: <INPUT TYPE=\"text\" NAME=\"new_comments\"><BR> +\n"; print "VALUE=\"$comments\">$comments<BR>\n"; } else { if ($query->param('new_name')) { print "Name: <INPUT TYPE=\"text\" NAME=\"new_name\" "; print "VALUE=\"", $query->param('new_name'), "\"><BR>\n"; print "Email: <INPUT TYPE=\"text\" NAME=\"new_email\" "; print "VALUE=\"", $query->param('new_email'), "\"><BR>\n"; print "Comments: <INPUT TYPE=\"text\" NAME=\"new_comments\" + "; print "VALUE=\"", $query->param('new_comments'), "\"><BR>\n +"; } else { print "Name: <INPUT TYPE=\"text\" NAME=\"new_name\" "; print "VALUE=\"", $query->param('name'), "\"><BR>\n"; print "Email: <INPUT TYPE=\"text\" NAME=\"new_email\" "; print "VALUE=\"", $query->param('email'), "\"><BR>\n"; print "Comments: <INPUT TYPE=\"text\" NAME=\"new_comments\" + "; print "VALUE=\"", $query->param('comments'), "\"><BR>\n"; } } } print "<INPUT TYPE=\"hidden\" NAME=\"name\" "; print "VALUE=\"" . $query->param('name') . "\">\n"; print "<INPUT TYPE=\"hidden\" NAME=\"email\" "; print "VALUE=\"" . $query->param('email') . "\">\n"; print "<INPUT TYPE=\"hidden\" NAME=\"comments\" "; print "VALUE=\"" . $query->param('comments') . "\">\n"; print "<INPUT TYPE=\"submit\" VALUE=\"submit\">\n"; print "</FORM>\n</P>\n"; sub valid_form { $return_code = 1; if (!$query->param('new_name')) { print "You must enter a name.<BR>\n"; $return_code = 0; } if (!$query->param('new_email')) { print "You must enter an email address.<BR>\n"; $return_code = 0; } if (!$query->param('comments')) { print "You must enter some comments.<BR>\n"; $return_code =0; } return $return_code; sub print_record_list { open (GUESTS, "> $guest_file") or die "Can't open guest file: $!"; while (<GUESTS>) { chomp; ($name, $email, $comments) = split ('\|\|'); print "<P>\n"; print "<FORM>\n"; print "Name: $name<BR>\n"; print "Email: $email<BR>\n"; print "Comments: $comments<BR>\n"; print "<INPUT TYPE=\"hidden\" NAME=\"name\" VALUE=\"$name\">\n"; print "<INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=\"$email\">\n"; # +"; print "<INPUT TYPE=\"hidden\" NAME=\"comments\" VALUE=\"$comment\">\n +"; print "<INPUT TYPE=\"submit\" VALUE=\"Edit this entry\">\n"; print "</FORM>\n"; print "</P>\n"; } } sub print_page_end { print "</BODY>\n</HTML>\n"; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://683418]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-03-19 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found