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

Re: [PBML] Reading from and writing to a file on a Linux machine

Expand Messages
  • Don Smith
    Charles, Thanks for your response. You are right. I did make an error in the working code that I posted. I explained my error and posted the complete code
    Message 1 of 5 , Dec 31, 2001
    • 0 Attachment
      Charles,

      Thanks for your response. You are right. I did make an error in the
      "working code" that I posted. I explained my error and posted the complete
      code (that actually does work!) in a subsequent message. You'll note my
      working code uses strict and includes your "CGI::Carp 'fatalsToBrowser' "
      line. I have learned a few things from you and the other kind folks on this
      message board.

      One question I have now is, the directories I create using this script are
      fully fuctional, but I cannot delete them. I can read, write, execute,
      rename, but I cannot chmod or delete them. I get a "550 Access denied"
      error.

      I suspect it has something to do with the Linux operating system and file
      permissions and nothing to do with Perl unless I'm leaving something out of
      my script that is obviously important.

      Just thought I'd ask.

      Its 12:41AM on Jan 1, 2002 here in Nova Scotia, Canada. Happy New Year to
      all!

      Don


      ----- Original Message -----
      From: "Charles K. Clarkson" <cclarkson@...>
      To: <perl-beginner@yahoogroups.com>
      Sent: Monday, December 31, 2001 4:34 PM
      Subject: Re: [PBML] Reading from and writing to a file on a Linux machine


      > "Don Smith" <dmsmith@...>
      >
      > : Greetings Folks!
      > :
      > : Once again, I come to you for help!
      > :
      > : I'm writing a rather long program that has a component that
      > : opens a file, checks to see if the directory name the user
      > : entered ($direcn) exists and if so, generates an error
      > : message, otherwise, it writes the directory name ($direcn)
      > : into the list.
      > :
      > : The script below, from my Windows machine works great,
      > : which surprised the heck out of me!
      > :
      > : The problem I'm having is getting it to run on my Linux
      > : machine. I get the dreaded "500 Internal Server Error".
      > :
      > : I've spent hours trying different things, including
      > : commenting it out line by line, adding in $foo->header,
      > : taking it out again, etc., etc. etc.
      > :
      > : If I comment this whole script out, the rest of the very
      > : long program works fine on the linux machine, so I know
      > : the problem is somewhere in this segment.
      > :
      > : I'm at a loss for why it isn't working on Linux. I'm
      > : sure one of you will take a look at it and my mistake
      > : will be glaringly obvious to you, but I'm really new to
      > : perl and even less experienced with the Linux operating
      > : system.
      >
      > I think you're telling tales. The code below
      > doesn't work. I assume that your frustration led you to
      > paste altered code instead of working code. However,
      > I made some comments about the code you sent (see below).
      >
      > To correct the '500' server errors try:
      >
      > Make sure the shebang line is at the beginning of
      > the file.
      >
      > #!/usr/bin/perl
      >
      > Make certain file permissions are set correctly.
      > use chmod on *nix systems.
      >
      > Make sure you're uploading in ASCII mode. Some
      > ftp programs are only set to load text files in
      > ASCII mode and you have to tell them to treat
      > ..pl and .pm files the same as .htm* and .txt files
      >
      > Place this line near the top of your script:
      > use CGI::Carp 'fatalsToBrowser';
      >
      > :
      > : Thanks in advance. The scripts are below.
      > :
      > : Don
      > :
      > :
      > : Windows Version - works fine
      > : # -------------------------------------------->>>
      > : my $filename = "c:/apache/cgi-bin/listing.dat";
      >
      > Don't use double quotes when single quotes will do.
      > Interpolation takes up time. Help poor old perl out
      > with:
      >
      > my $filename = 'c:/apache/cgi-bin/listing.dat';
      >
      > : open (FILEHANDLE, "<$filename") || die "Cannot open $filename.";
      >
      > Try ending the die with ' $!' for more desriptive errors:
      > die "Cannot open $filename: $!";
      >
      > : while (<FILEHANDLE>) {
      >
      > This sets $_ to the current line.
      >
      > : chomp $direcn;
      >
      > $direcn has not been defined, it is set to undef.
      > This chomps that same undef value for each line in
      > the file. chomp is useless when applied more than
      > once.
      >
      > : next unless /\b$direcn\b/i;
      >
      > This compares the undef value in $direcn to $_
      > (the current line). I doubt that's what you wanted
      > to do.
      >
      > : # print "Content-type: text/html\n\n";
      > : #commented out on
      > : Windows machine
      > : if ($direcn ne ""){
      > : print "<BR><BR><BR><BR><Center><H1>Sorry,
      > : the directory name \"" . $direcn . "\" is in
      > : use.</H1><BR><H2>Please click your browser's back
      > : button and enter another directory name.</H2></Center>";
      >
      > This could be re-written as:
      >
      > print qq|
      > Content-type: text/html\n\n<br><br><br><br>
      > <center>
      > <h1>Sorry, the directory name "$direcn" is in use.</h1>
      > <h2>Please click your browser's back button and
      > enter another directory name.</h2>
      > </center>|;
      >
      > Note that "Content-type: text/html\n\n" will be
      > printed *every* time there is a successful match, not
      > just once (which is what I assume you intended.)
      >
      > : $test = "1";
      >
      > $test = 1;
      >
      > : }
      > : }
      > : close FILEHANDLE;
      > :
      > : if ($test ne "1"){
      >
      > unless ($test) {
      > or:
      > if ($test != 1) {
      >
      > : open (FILEHANDLE2, ">>$filename")
      > : || die "Cannot open $filename.";
      > :
      > : print FILEHANDLE2 "$direcn\n";
      > : close FILEHANDLE2;
      >
      > You're missing the closing '}'
      > }
      >
      >
      > HTH,
      > Charles K. Clarkson
      > Clarkson Energy Homes, Inc.
      > 254 968-8328
      >
      >
      > The other night I was lying in bed, looking up at the stars, and I
      wondered,
      > "Where the heck is my ROOF?!?"
      > - Steven Wright
      >
      >
      >
      >
      >
      > Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html
      >
      > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
      >
      >


      ---
      Outgoing mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.310 / Virus Database: 171 - Release Date: 12/19/01
    Your message has been successfully submitted and would be delivered to recipients shortly.