Hello Monks, I have a simple html form.(Month Day Year Title and Message) input fields are used.
<form method="POST" action="http://www.dom.com/cgi-local/events.cgi"> <input type="hidden" name="action" value="preview"> <input type="submit" value="Preview" name="B1"> <input type="reset" value="Reset" name="B2"> </form>
When the form is submited the cgi script displays the variable information and formatting correctly.
#!/usr/local/bin/perl -w use strict; use diagnostics; use CGI qw(:standard); my $q = new CGI; my $action = $q->param('action'); ############################# #initialize form variables ############################# #my $uniq_number = &uniqueid; my $month = param('month'); my $date = param('date'); my $year = param('year'); my $title = param('title'); my $message = param('message'); my $placement = param('placement'); #PLACES NEW EVENT BEFORE OR AFTER EXISTING EVENTS ################################ # variables for storage ############################### my $data = join '::', $month,$date,$year,$title,$message; my $addfile = "events.txt"; my $line = ""; ###################################### #BEGIN COUNTCURRENTRECORDS SUBROUTINE ###################################### open(FILE, "$addfile"); my @lines = <FILE>; close(FILE); my $num = @lines; ###################################### if($action =~ /add_event/i){ &store_event; } ############################## # Print New Event for approval ############################## # Add the event passed variables from the add event page print header(), start_html(-title=>'CGI Example Script'), h2('New Parish Event!'), "<HR> <table border='0' width='100%'> <tr> <td width='100%'> <table border='1' width='100%'> <tr> <td width='100%'> <table border='1' width='100%'> <tr> <td width='22%'> <font SIZE='+1'color='gray'><B>$month $date, $year</B> </font></td> <td width='78%'> <font SIZE='+1'color='black'> <B>$title</B></font></td> </tr> </table> </td> </tr> <tr> <td width='800%'><font SIZE='2'>$message</font> </td> </tr> </table> </td> </tr> </table> <BR> <form action method='post'> <input type='hidden' name='action' value='add_event'> <input type='submit' value=' Publish new event '> <BR> <INPUT type='button' value='Continue'onClick='history.go(-1)'> </form>", end_html(); ##################################### #could be sub for saving data #################################### ##################################### # Open the file for appending ################################### sub store_event{ if ($placement eq "beg") { open (FH, "<events.txt") || die "could not open file: $!"; my @ODB = <FH>; close (FH); my $newline = "$data"; open (NFH, ">events.txt") || die "could not open file 2: $!"; print NFH "$newline" . "\n"; foreach $line (@ODB) { print NFH "$line"; } close (NFH); } else { open (OUT, ">>$addfile") or die "Can't open $addfile\n"; print OUT "$data\n"; close OUT; } } exit (0);
At this point I wanted to be able to write the variables to a file or go back and continue editing. But I am still new to perl and I am having a lot of trouble. Thanks for any help Cal

In reply to saving data problem by cal

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.