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

RE: [PBML] More CMS

Expand Messages
  • Charles K. Clarkson
    Hudson T Clark wrote: Before we look at the whole sub, lets outline the current decision tree: sub PostNews { . . . if( $_[2] && $_[3]
    Message 1 of 2 , Apr 29 2:47 PM
      Hudson T Clark <dark_archon1@...> wrote:


      Before we look at the whole sub, lets' outline
      the current decision tree:

      sub PostNews {
      .
      .
      .
      if( $_[2] && $_[3] ) {

      if( @newnews >= $_[3] ) {
      .
      .
      .
      goto a;

      } else {
      goto a;
      }

      } else {
      a: .
      .
      .
      }
      }

      All roads lead to a:. Which would be
      functionally equivalent to:

      sub PostNews {
      .
      .
      .
      if( $_[2] && $_[3] && @newnews >= $_[3] ) {
      .
      .
      .
      }
      .
      .
      .
      }

      ==============

      @newnews = reverse(@newnews);
      push @newnews, $_[0];
      @newnews = reverse(@newnews);

      Is equivalent to:

      unshift @newnews, $_[0];
      ==============

      @oldnews = reverse(@oldnews);
      until(scalar @newnews == ($_[3] - 1)) {
      my $tmp = pop @newnews;
      push @oldnews, $tmp;
      }
      @oldnews = reverse(@oldnews);

      Is equivalent to:

      unshift @oldnews, @newnews[$_[3] - 1 .. $#newnews];
      @newnews = @newnews[0 .. $_[3] - 2];
      ==============

      Post News sub:

      When called with two arguments,
      the first argument is the news and
      the second is the new news filename.

      When called with four arguments,
      the first argument is the news,
      the second is the new news filename,
      the third is the old news filename, and
      the fourth is the maximum number of posts
      allowed in the new news file.

      sub post_news {
      return unless @_== 2 or @_ == 4;

      # we are certain at leat two arguments were sent
      my( $news, $new_news_filename ) = @_[0, 1];

      # don't clobber open files
      local *FH;

      open FH, $new_news_filename or return;
      my @new_news = <FH>;
      close FH;

      if ( @_ == 4 && @new_news >= $_[3] ) {
      my( $old_news_filename, $max_news ) = @_[2, 3];

      open FH, $old_news_filename or return;
      my @old_news = <FH>;
      close FH;

      unshift @old_news, @new_news[$max_news - 1 .. $#new_news];
      @new_news = @new_news[0 .. $max_news - 2];

      open FH, ">$old_news_filename" or return;
      print FH @old_news;
      close FH;
      }

      open FH, ">$new_news_filename" or return;

      return print FH $news, @new_news;
      }

      __END__



      HTH,

      Charles K. Clarkson
      --
      Head Bottle Washer,
      Clarkson Energy Homes, Inc.
      Mobile Home Specialists
      254 968-8328
    Your message has been successfully submitted and would be delivered to recipients shortly.