Loading ...
Sorry, an error occurred while loading the content.

flat db, Web, NFS, hashes. Beginner questions

Expand Messages
  • cairpre409
    The project: Create a web tool where News items (policy changes) can be view, edited, inserted, searched (searching can come later). Also a text based
    Message 1 of 1 , Jun 1, 2003
      The project: Create a web tool where "News" items (policy changes)
      can be view, edited, inserted, searched (searching can come later).
      Also a text based version. I am actually working on this first, so I
      know the backend works

      The data will be on a different server from the web server. on a
      NFS share
      Security is not a major concern.

      I am planning this a perl backend, and perhaps a javascript or html
      form on the front.

      So far I have:
      1 perl script that gets data from user, assigns an index
      #, creates basic html code from it, and creates and updates log files
      I also have the basic code for a web form.

      Stuff I am not sure about.

      1. How do you append items to the top of a file? or better still
      insert in particular places?

      2. What is the process for extracting variable values from the html
      form, or javascript? I know there are modules, but I don't understand
      the process

      3. Some people have suggested that a hash would solve some of my
      problems. Although I understand array, and I know what a hash is I
      have a hard time visualizing how to use hashes. I would like to use
      the index number to reference the news item

      4. Should I create an amd mount, or simply transfer the data.

      5. Do I need multiple script, or can I stuff it all into one

      Here is my listing so far for refernce. It works, but I am just
      starting to work on the final part. Any advice is appreciated.
      By the way, I was only 1/2 through the first chapter of "learning
      perl" when I took on this project, and I don't really know any
      javascript. I am certainly learning though.

      #!/usr/bin/perl -w

      #this package "name space" thing is completely new to me. I don't
      # understand it

      package Webnews;
      use strict;

      #get previous index number
      my $infile = 'lastnews';
      open LOG, 'lastnews' or die "cannot open lastnews: $!";

      my $index = ( split ' ', <LOG> )[0];
      close LOG;


      #getting the variables

      my $name = get_user_info( "enter your name.\n" );
      my $brief = get_user_info( "enter brief subject.\n" );
      my $boss = get_user_info( "Where does info come from (ex:Mr.BIG).\n"

      sub get_user_info {
      my $prompt = shift;
      print $prompt;
      chomp( my $answer = <STDIN> );
      return $answer;

      # Get News

      my $newnews = 'some news\n';
      print "Please enter your news item. \nType lines. Type three
      semicolons \(\;\:\n";
      local $/ = ";;;\n";
      chomp( $newnews = <STDIN>);
      $newnews =~ s/\n/%%%/g;

      # Lets massage the news
      # ok lets not

      #my @records = ($index, $name, $brief ,$boss, $newnews);
      #print "$index\n";

      #write it to a file

      open LOG, '>>lastnews' or die "cannot append lastnews:$!";
      print LOG "$index :$name :$brief :$boss :$newnews\n";
      close LOG;

      my $bigfile = 'allnews';
      open MNLOG, '>>allnews' or die "cannot append to allnews: $!";
      print MNLOG "$index :$name :$brief :$boss :$newnews\n";
      close MNLOG;

      my $nnnfile = 'lastnews';
      open LLOG, '>lastnews' or die "cannot create to lastnews: $!";
      print LLOG "$index :$name :$brief :$boss :$newnews\n";
      close LLOG;

      # This log rotation is really horrible. Its only done
      # because I could not figure out how to properly read
      # from the end of a file

      # Time to create html snippets
      # first lets reformat the news

      my $formnews = $newnews;
      $formnews =~ s/%%%/\n/g;

      my $snippit = 'newsitem';
      open SNIP, '>newsitem' or die "cannot create newsitem: $1";
      print SNIP <<"EOF";
      <H6>Item#$index $name </H6>
      close SNIP;

      # Hashesh: trying to figure out the next steps

      #%Webnews::ournews = ();
      #$Webnews::ournews{$index} = $Webnews::records;

      you need a "lastnews" file for it to work.
      $ echo 0 > lastnews

      Thanks for any advice
    Your message has been successfully submitted and would be delivered to recipients shortly.