Phoenix.pm: Feeling stupid today

Shay Harding mekla at geocities.com
Thu Sep 16 18:18:26 CDT 1999


Hey everyone :)

Man this list has its ups and downs. One moment there are lots of
messages, the next dead. :(

Well, I ran into a problem today while coding and after figuring out
what it was I felt, well... dumb. It was so obvious, but not until I
figured it out, which is the way it usually goes I guess. Anyway I am
including the script in it's entirety (up to this point anyway) so you
can see it. I'm just wondering if anyone can see what the BIG, HUGE
error is in the following code. Just to let everyone know how dumb I
felt after this ordeal, it took me about 1-1/2 hours to figure it out.
It's been a long day.

I'm just posting this so others can avoid my same mistake (plus I want
to see some activity on the list)  :)


--------------------- Start code ------------------------

#!/usr/bin/perl5


  BEGIN{

      *width = \80;

      sub mopendir($);
      sub mopenfile($;$);
      sub get_core_dir($);
      sub center($);
      sub get_header($);

      sub mopendir($){
          my ($dir) = @_;
          opendir(DIR,$dir) || die("Cannot open directory $dir ($!)\n");
          return *DIR;
      }

      sub mopenfile($;$){
          my ($file,$mode) = @_;

          if (!$mode){
              if (!-e $file){
                  open (FILE,">$file") || die("Cannot open file $file ($!)\n");
              }else{
                  open (FILE,">>$file") || die("Cannot open file $file ($!)\n");
              }
          }else{
              open (FILE,$file) || die("Cannot open file $file ($!)\n");
          }
          return *FILE;
      }

      sub get_core_dir($){
          my ($dir) = @_;
          $dir =~ s/(^.*)(\/)(.*$)/$3/g;
          return $dir;
      }

      sub center($){
          my ($string) = @_;
          my $pad = ($width-length($string))/2;
          $pad =~ s/\..*//g;
          my $spaces = " "x$pad;
          return ($spaces.$string.$spaces);
      }

      sub get_header($){
          my ($string) = @_;
          my $char = "-";
          my $pad = (($width-length($string))/2)-1;
          $pad =~ s/\..*//g;
          my $spaces = "$char"x$pad;
          return ($spaces." $string ".$spaces);
      }

  }


  my $base_dir = '/var/checks';
  my $access_error = $base_dir."/AccessError";
  my $database_error = $base_dir."/DatabaseError";
  my $file_error = $base_dir."/FileError";
  my $signup_form_error = $base_dir."/SignupFormError";
  my $bank_error = $signup_form_error."/BankError";
  my $socket_error = $base_dir."/SocketError";
  my $session_logs = $base_dir."/SessionLogs";
  my $webmaster_logs = $base_dir."/WebmasterLogs";
  my $archive_dir = $base_dir."/ARCHIVE";
  chomp($NOW = `date +"%Y_%m_%d"`);


  &get_access_dir();


  sub get_access_dir(){
      local (*D) = mopendir($access_error);
      my $core_dir = get_core_dir($access_error);
      my $archive = $archive_dir."/".$core_dir."_$NOW";

      local (*F) = mopenfile($archive);

      while (my $filename = readdir(*D)){
          if ($filename =~ /^\d+-\d+-\d+$/){
              my $header = get_header($filename);
              print F "$header\n\n";

              local (*FF) = mopenfile("$access_error/$filename","R");
              my @data = <FF>;
              close (*FF);

              if (scalar(@data) < 1){ 
                  print "$filename => No data\n";
              }
              else{
                  print "$filename => ", at data,"\n";
              
              }
          }   
      }

      closedir(*D);
      close(*F);
  }   


-------------------------- End code -----------------------------


--

Shay



More information about the Phoenix-pm mailing list