View Single Post
  #2 (permalink)  
Old 01-20-04, 10:09 AM
Chas Chas is offline
Coding Addict
 
Join Date: Oct 2003
Location: California
Posts: 359
Thanks: 0
Thanked 0 Times in 0 Posts
Hi abtimoteo,

Quote:
Originally Posted by abtimoteo
option 1: write each new submission to the beginning of the flat file. how can this be done under the following conditions?

a. my data is in binary mode.
b. a perl module is out of the question because of the restrictions imposed by my web host.
a: Why are you using binary for this?
b: See comments below on modules.

Quote:
Originally Posted by abtimoteo
option 2: reverse the array of news submissions - again, under conditions a and b above, before it is written to the file. i have tried doing it several times but ...
See the reverse pod

Code:
read (STDIN, $FormInputs, $ENV{'CONTENT_LENGTH'});
@NameValuePairs = split (/&/, $FormInputs);
for ($i = 0; $NameValuePairs[$i]; $i++)
  {
    ($Name, $Value) = split(/=/, $NameValuePairs[$i]);
    $Name =~ tr/+/ /;
    $Value =~ tr/+/ /;
    $Name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $Value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;   
    # Convert newlines to linebreaks.
    $Value =~ s/\n/<br>/g;
    $NameValuePairs[$i] = $Value;
  }

$ThisNewsSubmission = pack ("a50a50a150a2500l" , @NameValuePairs);
You really should be using the CGI.pm module to parse your input. Unless you are using a very old version of Perl this is a standard module.

Code:
# WRITE TO A FLAT FILE.

# Open the flat file named "xyzNewsSubmissions.dat" for appending.
# Create and upload the file manually.

open (NEWSSUBMISSIONS, ">>xyzNewsSubmissions.dat")
  || die "Could not open file: $!\n";

# Select NEWSSUBMISSIONS as output device.

select (NEWSSUBMISSIONS);

print NEWSSUBMISSIONS $ThisNewsSubmission;

# Close the file.

close (NEWSSUBMISSIONS)
  || die "Could not close file: $!\n";[/QUOTE]
If you structured your data (i.e. tab or | deliminated) it would be easier to m/(add|edit|delete|sort)/; when it comes time to work with it:

Code:
year|month|day|time|Tite of new|artice text|posted by|whatever else|yadayadayada
Then you can do just about anything you want with it at that point.

~Charlie
Reply With Quote