in reply to Parsing e-mail and building HTML

A database would be good, but you can put it all in a file and use "|" to deliminate the fields (it is very unlikly "|" will be found in a text file). I would then write a script that would read the file and put the values in an array and use a foreach loop to create the html.
# to read from the file open (FILE,"</myfile"); flock FILE,1; while (<FILE>){ ($tmp_state,$tmp_job) = split /\|/,$_; push @job, $tmp_job; } # sort @job or @state how you would like # Print html header foreach $tmp_job(@job){ # Print html with @job for a value and } # Print html footer
That should be a basic outline for your code.

PS A good way to learn how to write a program is to write all the steps you need to do in comments. Then you can write the code that will do what you wrote in your comment.

#open file #lock file #read user input #write user input to file #close file #open file open (FILE,"</myfile"); #lock file flock FILE,2; #read user input $input = <STDIN>; #write user input to file print FILE "$input"; #close file close FILE;

Replies are listed 'Best First'.
RE: Re: Parsing e-mail and building HTML
by athomason (Curate) on Jul 06, 2000 at 00:38 UTC
    it is very unlikly "|" will be found in a text file

    Relying on unlikelihoods is a dangerous programming practice, especially when you have a concern for security. You'd be much better off escaping the string or validating the input to guarantee your delimiter can't be found within your data. However, this can be a significant pain, so a good compromise is to use a multi-character delimiter instead of a single character, say '|||'. This is a minimal change which does a lot more to protect your data.

RE: Re: Parsing e-mail and building HTML
by mrmick (Curate) on Jul 05, 2000 at 20:59 UTC
    I wish I had saved one of todays votes.. (oh well, tomorrow is another day).
    In addition to c-era's reply, I would like to add that you could also write a Perl program to read your customers' email messages and put the data into the appropriate text file(s), thus saving you considerable effort each time new data arrives.
    This is assuming, of course, that there is a somewhat consistent template or format in which you receive your data.
      In addition to c-era's reply, I would like to add that you could also write a Perl program to read your customers' email messages and put the data into the appropriate text file(s), thus saving you considerable effort each time new data arrives.
      This is assuming, of course, that there is a somewhat consistent template or format in which you receive your data.


      Yes, this is also what I would like to do. Could I just read the e-mail then start processing from there with out putting into a textfile first? Another thing that I didn't make clear above was that the two main files (sorted by state & job) are already built, and the new information will be added as a row in a pre-existing table. Perhaps I could post urls of sample pages, and a sample e-mail (which comes from a database, so they're all the same).

      andy j.
        I think a better solution is to refer your customers to an online form. This way you can have more control over the number and delimiting of fields, and the incoming data will be much easier to parse. You could use CGI.pm for the form generation and handling.
        The problem with letting your customers send an email (as compared to a form) with the information is that you can't really enforce how the data is formatted, making it difficult to predict reliably.