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

Re: [PBML] Beginner needs help! Writing to file using Perl...

Expand Messages
  • Greg Flowers
    Check the permissions on the directory/file that you are trying to write to.
    Message 1 of 6 , Apr 9, 2000
    • 0 Attachment
      Check the permissions on the directory/file that you are trying to write to.

      Angi wrote:

      > Hi,
      >
      > I should mention that I am a beginner. I would also like
      > to apologize if anyone has seen this message already, as
      > I posted on a few other lists as well. I am on an NT server,
      > running Perl 5.
      >
      > Although it appears that the script works, there are no
      > errors, and the redirection works as planned. LWP::Simple;
      > does work. I was able to print the page to the screen. I
      > want to print it to a file instead of the page. The file
      > it should print to (and the url to grab) is being sent
      > via a form. The file does exist. I hope that someone can
      > offer some suggestions. BTW, I also tried entering the actual
      > filename and a line of text to write to the file, just to
      > test it, and it did not work either. My file remains blank!
      >
      > Here is the code I am using:
      >
      > #!/perl/bin/perl
      >
      > use LWP::Simple;
      > &get_form;
      > $URL = $INPUT{'url'};
      > $TEMPFILE = $INPUT{'tempfile'};
      > $KEYW1 = $INPUT{'keyw1'};
      > $KEYW2 = $INPUT{'keyw2'};
      > $KEYW3 = $INPUT{'keyw3'};
      > $REDIRECTURL = 'testred.asp';
      > $ERRREDIRECTURL = 'metalyzerr.asp';
      > $CONTENT = get($URL);
      >
      > if (head($URL)) {
      >
      > print "Location: $ERRREDIRECTURL\n\n";
      >
      > } else {
      >
      > open (HANDLE, ">>$TEMPFILE");
      > print HANDLE $CONTENT;
      > close (HANDLE);
      > print "Location:
      > $REDIRECTURL?url=$URL&filename=$TEMPFILE&keyw1=$KEYW1&keyw2=$KEYW2&keyw3=$KEYW3\n\n";
      >
      > }
      >
      > exit;
      >
      > sub get_form {
      > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
      > @pairs = split(/&/, $buffer);
      > foreach $pair (@pairs) {
      > ($name, $value) = split(/=/, $pair);
      > $value =~ tr/+/ /;
      > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      > if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
      > else { $INPUT{$name} = $value; }
      > }
      > }
      >
      > Thank you in advance,
      >
      > Angi [mailto:angib@...]
      >
      > ------------------------------------------------------------------------
      > @Backup- Protect and Access your data any time, any where on the net.
      > Try @Backup FREE and recieve 300 points from mypoints.com Install now:
      > http://click.egroups.com/1/2345/1/_/12898/_/955300781/
      > ------------------------------------------------------------------------
    • Angi
      Hi, The permissions have been set to execute, there is read/write access on the directory. I am able to open and write to this file using ASP, so I am assuming
      Message 2 of 6 , Apr 9, 2000
      • 0 Attachment
        Hi,

        The permissions have been set to execute, there is read/write
        access on the directory. I am able to open and write to this
        file using ASP, so I am assuming that the problem lies within
        my code.

        Thanks,

        Angi [mailto:angib@...]

        Greg Flowers wrote:
        >
        > Check the permissions on the directory/file that you are trying to write to.
        >
        > Angi wrote:
        >
        > > Hi,
        > >
        > > I should mention that I am a beginner. I would also like
        > > to apologize if anyone has seen this message already, as
        > > I posted on a few other lists as well. I am on an NT server,
        > > running Perl 5.
        > >
        > > Although it appears that the script works, there are no
        > > errors, and the redirection works as planned. LWP::Simple;
        > > does work. I was able to print the page to the screen. I
        > > want to print it to a file instead of the page. The file
        > > it should print to (and the url to grab) is being sent
        > > via a form. The file does exist. I hope that someone can
        > > offer some suggestions. BTW, I also tried entering the actual
        > > filename and a line of text to write to the file, just to
        > > test it, and it did not work either. My file remains blank!
        > >
        > > Here is the code I am using:
        > >
        > > #!/perl/bin/perl
        > >
        > > use LWP::Simple;
        > > &get_form;
        > > $URL = $INPUT{'url'};
        > > $TEMPFILE = $INPUT{'tempfile'};
        > > $KEYW1 = $INPUT{'keyw1'};
        > > $KEYW2 = $INPUT{'keyw2'};
        > > $KEYW3 = $INPUT{'keyw3'};
        > > $REDIRECTURL = 'testred.asp';
        > > $ERRREDIRECTURL = 'metalyzerr.asp';
        > > $CONTENT = get($URL);
        > >
        > > if (head($URL)) {
        > >
        > > print "Location: $ERRREDIRECTURL\n\n";
        > >
        > > } else {
        > >
        > > open (HANDLE, ">>$TEMPFILE");
        > > print HANDLE $CONTENT;
        > > close (HANDLE);
        > > print "Location:
        > > $REDIRECTURL?url=$URL&filename=$TEMPFILE&keyw1=$KEYW1&keyw2=$KEYW2&keyw3=$KEYW3\n\n";
        > >
        > > }
        > >
        > > exit;
        > >
        > > sub get_form {
        > > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
        > > @pairs = split(/&/, $buffer);
        > > foreach $pair (@pairs) {
        > > ($name, $value) = split(/=/, $pair);
        > > $value =~ tr/+/ /;
        > > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        > > if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
        > > else { $INPUT{$name} = $value; }
        > > }
        > > }
        > >
        > > Thank you in advance,
        > >
        > > Angi [mailto:angib@...]
        > >
        > > ------------------------------------------------------------------------
        > > @Backup- Protect and Access your data any time, any where on the net.
        > > Try @Backup FREE and recieve 300 points from mypoints.com Install now:
        > > http://click.egroups.com/1/2345/1/_/12898/_/955300781/
        > > ------------------------------------------------------------------------
        >
        > ------------------------------------------------------------------------
        > Get your bargains at AndysGarage.com!
        > http://click.egroups.com/1/2579/1/_/12898/_/955301212/
        > ------------------------------------------------------------------------
      • Aram Mirzadeh
        Just as a test, try writing a very simple perl program and just opened the file and closes the file. See if that works, because the code looks right.
        Message 3 of 6 , Apr 9, 2000
        • 0 Attachment
          Just as a test, try writing a very simple perl program and just opened the
          file and closes the file. See if that works, because the code looks right.

          #!/usr/local/bin/perl

          open (FILE,"> TEST");
          print FILE "test line\n";
          close (FILE);

          Aram

          -----Original Message-----
          From: Angi [mailto:angib@...]
          Sent: Sunday, April 09, 2000 1:36 PM
          To: perl-beginner@egroups.com
          Subject: Re: [PBML] Beginner needs help! Writing to file using Perl...


          Hi,

          The permissions have been set to execute, there is read/write
          access on the directory. I am able to open and write to this
          file using ASP, so I am assuming that the problem lies within
          my code.

          Thanks,

          Angi [mailto:angib@...]

          Greg Flowers wrote:
          >
          > Check the permissions on the directory/file that you are trying to write
          to.
          >
          > Angi wrote:
          >
          > > Hi,
          > >
          > > I should mention that I am a beginner. I would also like
          > > to apologize if anyone has seen this message already, as
          > > I posted on a few other lists as well. I am on an NT server,
          > > running Perl 5.
          > >
          > > Although it appears that the script works, there are no
          > > errors, and the redirection works as planned. LWP::Simple;
          > > does work. I was able to print the page to the screen. I
          > > want to print it to a file instead of the page. The file
          > > it should print to (and the url to grab) is being sent
          > > via a form. The file does exist. I hope that someone can
          > > offer some suggestions. BTW, I also tried entering the actual
          > > filename and a line of text to write to the file, just to
          > > test it, and it did not work either. My file remains blank!
          > >
          > > Here is the code I am using:
          > >
          > > #!/perl/bin/perl
          > >
          > > use LWP::Simple;
          > > &get_form;
          > > $URL = $INPUT{'url'};
          > > $TEMPFILE = $INPUT{'tempfile'};
          > > $KEYW1 = $INPUT{'keyw1'};
          > > $KEYW2 = $INPUT{'keyw2'};
          > > $KEYW3 = $INPUT{'keyw3'};
          > > $REDIRECTURL = 'testred.asp';
          > > $ERRREDIRECTURL = 'metalyzerr.asp';
          > > $CONTENT = get($URL);
          > >
          > > if (head($URL)) {
          > >
          > > print "Location: $ERRREDIRECTURL\n\n";
          > >
          > > } else {
          > >
          > > open (HANDLE, ">>$TEMPFILE");
          > > print HANDLE $CONTENT;
          > > close (HANDLE);
          > > print "Location:
          > >
          $REDIRECTURL?url=$URL&filename=$TEMPFILE&keyw1=$KEYW1&keyw2=$KEYW2&keyw3=$KE
          YW3\n\n";
          > >
          > > }
          > >
          > > exit;
          > >
          > > sub get_form {
          > > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
          > > @pairs = split(/&/, $buffer);
          > > foreach $pair (@pairs) {
          > > ($name, $value) = split(/=/, $pair);
          > > $value =~ tr/+/ /;
          > > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
          > > if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
          > > else { $INPUT{$name} = $value; }
          > > }
          > > }
          > >
          > > Thank you in advance,
          > >
          > > Angi [mailto:angib@...]
          > >
          > > ------------------------------------------------------------------------
          > > @Backup- Protect and Access your data any time, any where on the net.
          > > Try @Backup FREE and recieve 300 points from mypoints.com Install now:
          > > http://click.egroups.com/1/2345/1/_/12898/_/955300781/
          > > ------------------------------------------------------------------------
          >
          > ------------------------------------------------------------------------
          > Get your bargains at AndysGarage.com!
          > http://click.egroups.com/1/2579/1/_/12898/_/955301212/
          > ------------------------------------------------------------------------

          ------------------------------------------------------------------------
          Special Offer-Earn 300 Points from MyPoints.com for trying @Backup
          Get automatic protection and access to your important computer files.
          Install today:
          http://click.egroups.com/1/2344/1/_/12898/_/955301999/
          ------------------------------------------------------------------------
        • Ingenue
          Did you use die to see if there s any problems that get put into $! ? open (F, /path/to/file ) or die $! n ; ... From: Angi
          Message 4 of 6 , Apr 9, 2000
          • 0 Attachment
            Did you use "die" to see if there's any problems that get put into '$!' ?

            open (F, "> /path/to/file") or die "$!\n";



            ----- Original Message -----
            From: "Angi" <angib@...>
            To: <perl-beginner@egroups.com>
            Sent: Sunday, April 09, 2000 10:15 AM
            Subject: [PBML] Beginner needs help! Writing to file using Perl...


            > Hi,
            >
            > I should mention that I am a beginner. I would also like
            > to apologize if anyone has seen this message already, as
            > I posted on a few other lists as well. I am on an NT server,
            > running Perl 5.
            >
            > Although it appears that the script works, there are no
            > errors, and the redirection works as planned. LWP::Simple;
            > does work. I was able to print the page to the screen. I
            > want to print it to a file instead of the page. The file
            > it should print to (and the url to grab) is being sent
            > via a form. The file does exist. I hope that someone can
            > offer some suggestions. BTW, I also tried entering the actual
            > filename and a line of text to write to the file, just to
            > test it, and it did not work either. My file remains blank!
            >
            > Here is the code I am using:
            >
            > #!/perl/bin/perl
            >
            > use LWP::Simple;
            > &get_form;
            > $URL = $INPUT{'url'};
            > $TEMPFILE = $INPUT{'tempfile'};
            > $KEYW1 = $INPUT{'keyw1'};
            > $KEYW2 = $INPUT{'keyw2'};
            > $KEYW3 = $INPUT{'keyw3'};
            > $REDIRECTURL = 'testred.asp';
            > $ERRREDIRECTURL = 'metalyzerr.asp';
            > $CONTENT = get($URL);
            >
            > if (head($URL)) {
            >
            > print "Location: $ERRREDIRECTURL\n\n";
            >
            > } else {
            >
            > open (HANDLE, ">>$TEMPFILE");
            > print HANDLE $CONTENT;
            > close (HANDLE);
            > print "Location:
            >
            $REDIRECTURL?url=$URL&filename=$TEMPFILE&keyw1=$KEYW1&keyw2=$KEYW2&keyw3=$KE
            YW3\n\n";
            >
            > }
            >
            > exit;
            >
            > sub get_form {
            > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
            > @pairs = split(/&/, $buffer);
            > foreach $pair (@pairs) {
            > ($name, $value) = split(/=/, $pair);
            > $value =~ tr/+/ /;
            > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
            > if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
            > else { $INPUT{$name} = $value; }
            > }
            > }
            >
            > Thank you in advance,
            >
            > Angi [mailto:angib@...]
            >
            > ------------------------------------------------------------------------
            > @Backup- Protect and Access your data any time, any where on the net.
            > Try @Backup FREE and recieve 300 points from mypoints.com Install now:
            > http://click.egroups.com/1/2345/1/_/12898/_/955300781/
            > ------------------------------------------------------------------------
            >
            >
          • Angi
            Hi, I just sent a reply about my directory path, and it seems that I should not have had a / before cgi-bin. Thanks to everyone who helped (on all lists!) Angi
            Message 5 of 6 , Apr 9, 2000
            • 0 Attachment
              Hi,

              I just sent a reply about my directory path, and
              it seems that I should not have had a / before
              cgi-bin. Thanks to everyone who helped (on all lists!)

              Angi

              Ingenue wrote:
              >
              > Did you use "die" to see if there's any problems that get put into '$!' ?
              >
              > open (F, "> /path/to/file") or die "$!\n";
              >
              > ----- Original Message -----
              > From: "Angi" <angib@...>
              > To: <perl-beginner@egroups.com>
              > Sent: Sunday, April 09, 2000 10:15 AM
              > Subject: [PBML] Beginner needs help! Writing to file using Perl...
              >
              > > Hi,
              > >
              > > I should mention that I am a beginner. I would also like
              > > to apologize if anyone has seen this message already, as
              > > I posted on a few other lists as well. I am on an NT server,
              > > running Perl 5.
              > >
              > > Although it appears that the script works, there are no
              > > errors, and the redirection works as planned. LWP::Simple;
              > > does work. I was able to print the page to the screen. I
              > > want to print it to a file instead of the page. The file
              > > it should print to (and the url to grab) is being sent
              > > via a form. The file does exist. I hope that someone can
              > > offer some suggestions. BTW, I also tried entering the actual
              > > filename and a line of text to write to the file, just to
              > > test it, and it did not work either. My file remains blank!
              > >
              > > Here is the code I am using:
              > >
              > > #!/perl/bin/perl
              > >
              > > use LWP::Simple;
              > > &get_form;
              > > $URL = $INPUT{'url'};
              > > $TEMPFILE = $INPUT{'tempfile'};
              > > $KEYW1 = $INPUT{'keyw1'};
              > > $KEYW2 = $INPUT{'keyw2'};
              > > $KEYW3 = $INPUT{'keyw3'};
              > > $REDIRECTURL = 'testred.asp';
              > > $ERRREDIRECTURL = 'metalyzerr.asp';
              > > $CONTENT = get($URL);
              > >
              > > if (head($URL)) {
              > >
              > > print "Location: $ERRREDIRECTURL\n\n";
              > >
              > > } else {
              > >
              > > open (HANDLE, ">>$TEMPFILE");
              > > print HANDLE $CONTENT;
              > > close (HANDLE);
              > > print "Location:
              > >
              > $REDIRECTURL?url=$URL&filename=$TEMPFILE&keyw1=$KEYW1&keyw2=$KEYW2&keyw3=$KE
              > YW3\n\n";
              > >
              > > }
              > >
              > > exit;
              > >
              > > sub get_form {
              > > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
              > > @pairs = split(/&/, $buffer);
              > > foreach $pair (@pairs) {
              > > ($name, $value) = split(/=/, $pair);
              > > $value =~ tr/+/ /;
              > > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
              > > if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
              > > else { $INPUT{$name} = $value; }
              > > }
              > > }
              > >
              > > Thank you in advance,
              > >
              > > Angi [mailto:angib@...]
              > >
              > > ------------------------------------------------------------------------
              > > @Backup- Protect and Access your data any time, any where on the net.
              > > Try @Backup FREE and recieve 300 points from mypoints.com Install now:
              > > http://click.egroups.com/1/2345/1/_/12898/_/955300781/
              > > ------------------------------------------------------------------------
              > >
              > >
              >
              > ------------------------------------------------------------------------
              > Whatever you want, chances are you'll find it at one of the hundreds
              > of sites in The PointClick Network--like Disney.com, eCost.com,
              > FogDog.com and many more. You get paid as you shop and an additional
              > 10% off any purchase, anytime.
              > http://click.egroups.com/1/2994/1/_/12898/_/955315106/
              > ------------------------------------------------------------------------
            • Ingenue
              Angi, You should use the absolute path to the file, not the relative one. For example: open (F, /home/www/foo.com/cgi-bin/temp/550330623.html ) or die
              Message 6 of 6 , Apr 10, 2000
              • 0 Attachment
                Angi,

                You should use the absolute path to the file, not the relative one.
                For example: open (F, "/home/www/foo.com/cgi-bin/temp/550330623.html") or
                die "$!\n";

                You can just use the path, "temp/550330623.html", but it's more secure if
                you do it the first way.


                ----- Original Message -----
                From: "Angi" <angib@...>
                To: <perl-beginner@egroups.com>
                Sent: Sunday, April 09, 2000 5:28 PM
                Subject: Re: [PBML] Beginner needs help! Writing to file using Perl...


                > Hi,
                >
                > Wow, this was different! I used the code you sent,
                > and I received a "No such file or directory" error.
                > At least now I know why I've had problems. Thanks!
                >
                > My file is /cgi-bin/temp/550330623.html
                > This script is in /cgi-bin/
                >
                > Did I reference the file incorrectly? Should it be
                > something like /temp/550330623.html instead? Thanks
                > again.
                >
                > Angi
                >
                > Ingenue wrote:
                > >
                > > Did you use "die" to see if there's any problems that get put into '$!'
                ?
                > >
                > > open (F, "> /path/to/file") or die "$!\n";
                > >
                > > ----- Original Message -----
                > > From: "Angi" <angib@...>
                > > To: <perl-beginner@egroups.com>
                > > Sent: Sunday, April 09, 2000 10:15 AM
                > > Subject: [PBML] Beginner needs help! Writing to file using Perl...
                > >
                > > > Hi,
                > > >
                > > > I should mention that I am a beginner. I would also like
                > > > to apologize if anyone has seen this message already, as
                > > > I posted on a few other lists as well. I am on an NT server,
                > > > running Perl 5.
                > > >
                > > > Although it appears that the script works, there are no
                > > > errors, and the redirection works as planned. LWP::Simple;
                > > > does work. I was able to print the page to the screen. I
                > > > want to print it to a file instead of the page. The file
                > > > it should print to (and the url to grab) is being sent
                > > > via a form. The file does exist. I hope that someone can
                > > > offer some suggestions. BTW, I also tried entering the actual
                > > > filename and a line of text to write to the file, just to
                > > > test it, and it did not work either. My file remains blank!
                > > >
                > > > Here is the code I am using:
                > > >
                > > > #!/perl/bin/perl
                > > >
                > > > use LWP::Simple;
                > > > &get_form;
                > > > $URL = $INPUT{'url'};
                > > > $TEMPFILE = $INPUT{'tempfile'};
                > > > $KEYW1 = $INPUT{'keyw1'};
                > > > $KEYW2 = $INPUT{'keyw2'};
                > > > $KEYW3 = $INPUT{'keyw3'};
                > > > $REDIRECTURL = 'testred.asp';
                > > > $ERRREDIRECTURL = 'metalyzerr.asp';
                > > > $CONTENT = get($URL);
                > > >
                > > > if (head($URL)) {
                > > >
                > > > print "Location: $ERRREDIRECTURL\n\n";
                > > >
                > > > } else {
                > > >
                > > > open (HANDLE, ">>$TEMPFILE");
                > > > print HANDLE $CONTENT;
                > > > close (HANDLE);
                > > > print "Location:
                > > >
                > >
                $REDIRECTURL?url=$URL&filename=$TEMPFILE&keyw1=$KEYW1&keyw2=$KEYW2&keyw3=$KE
                > > YW3\n\n";
                > > >
                > > > }
                > > >
                > > > exit;
                > > >
                > > > sub get_form {
                > > > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
                > > > @pairs = split(/&/, $buffer);
                > > > foreach $pair (@pairs) {
                > > > ($name, $value) = split(/=/, $pair);
                > > > $value =~ tr/+/ /;
                > > > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
                > > > if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
                > > > else { $INPUT{$name} = $value; }
                > > > }
                > > > }
                > > >
                > > > Thank you in advance,
                > > >
                > > > Angi [mailto:angib@...]
                > > >
                > >
                > ------------------------------------------------------------------------
                > > > @Backup- Protect and Access your data any time, any where on the net.
                > > > Try @Backup FREE and recieve 300 points from mypoints.com Install now:
                > > > http://click.egroups.com/1/2345/1/_/12898/_/955300781/
                > >
                > ------------------------------------------------------------------------
                > > >
                > > >
                > >
                > > ------------------------------------------------------------------------
                > > Whatever you want, chances are you'll find it at one of the hundreds
                > > of sites in The PointClick Network--like Disney.com, eCost.com,
                > > FogDog.com and many more. You get paid as you shop and an additional
                > > 10% off any purchase, anytime.
                > > http://click.egroups.com/1/2994/1/_/12898/_/955315106/
                > > ------------------------------------------------------------------------
                >
                > ------------------------------------------------------------------------
                > Whatever you want, chances are you'll find it at one of the hundreds
                > of sites in The PointClick Network--like Disney.com, eCost.com,
                > FogDog.com and many more. You get paid as you shop and an additional
                > 10% off any purchase, anytime.
                > http://click.egroups.com/1/2994/1/_/12898/_/955389292/
                > ------------------------------------------------------------------------
                >
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.