Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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"; } }

In reply to Re: problems editing a flat-file | my input to your effort by andr321
in thread problems editing a flat-file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-19 04:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found