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

Script is not working in CGI but is working locally

Expand Messages
  • Irek Rybark
    Hi! I am new to perl and CGI. I am even not sure that this is more perl or CGI problem. I am trying to use CSV module by Christopher Rath
    Message 1 of 4 , Aug 3, 2004
    • 0 Attachment
      Hi!
      I am new to perl and CGI. I am even not sure that this is
      more perl or CGI problem.

      I am trying to use CSV module by Christopher Rath
      http://rath.ca/Misc/Perl_CSV/index.shtml
      to parse some comma separated file.
      My problem is that my script is **not working on a server**,
      however is **working on my local box** (W2k command prompt).

      This is an output on my box:
      ================================================
      C:\Perl\lib\CSV-2\Demo_App>perl CSV_test.cgi
      Content-type: text/html
      Item Number,Item Name,Item Description,Item Type
      <p> J00E0001, Tirbal Necklace, Charming tribal necklace </p>
      <p> J00T0001, Jade Necklace, Beautiful Chinese jade necklace </p>
      ================================================

      This is an output from HTTP server: (you can see it with your own
      eyes: http://sutherlandstudios.netfirms.com/cgi/cgierr.pl/cgi-
      bin/CSV_test.cgi)
      ================================================
      Content-type: text/html Item Number,Item Name,Item Description,Item
      Type Oups! Some fields are missing from the input file.end
      ================================================
      What could be wrong?
      I appreciate any feedback,
      Irek



      Perl version: 5.6.1 (local and the server)
      Script to download: http://sutherlandstudios.netfirms.com/CSV_test.cgi

      Actually, suspecting some problems with calling functions from
      external module I put test code into CGI module.

      Key part of the scrit follows:
      ================================================
      #!/usr/bin/perl -w
      use strict;
      print "Content-type: text/html\n";
      $CSV::Delimiters = undef;
      my(%CSVDefaultColumnMapping) = ("" => -1);

      my($ITEM_NUM) = "Item Number";
      my($ITEM_NAME) = "Item Name";
      my($ITEM_DESC) = "Item Description";
      my($ITEM_TYPE) = "Item Type";

      my($input) = "items.csv"; #$ARGV[0];
      my($item_type) = "NECKLACE"; #$ARGV[1];

      if (!open(INPUT, "$input")) {
      die "$0: ERROR, cannot open input file, $input\n"
      ."\tno data generated.\n";
      } else {
      my($firstLine) = scalar(<INPUT>);
      my(%CSVfields) = CSVinit($firstLine);

      print$firstLine;

      if (! CSVvalidate(\%CSVfields, $ITEM_NUM, $ITEM_NAME, $ITEM_DESC,
      $ITEM_TYPE)) {
      # die "Some fields are missing from the input file.";
      print "Oups! Some fields are missing from the input file.";
      } else {
      my(@record); # Where we'll store parsed records.
      my($outrec); #Output record (a string).

      while (<INPUT>) {
      @record = CSVsplit($_);
      if ("\U$record[$CSVfields{$ITEM_TYPE}]"
      eq "\U$item_type") {
      printf "<p> %s, %s, %s </p>\n",
      "$record[$CSVfields{$ITEM_NUM}]",
      "$record[$CSVfields{$ITEM_NAME}]",
      "$record[$CSVfields{$ITEM_DESC}]";
      }
      }
      }
      }
      ##### THE REST HAS BEEN REMOVED
    • daymobrew@yahoo.com
      ... So, it seems that CSVvalidate() is failing. One possibility - the input file was uploaded by ftp as binary instead of ascii? It might make (though
      Message 2 of 4 , Aug 4, 2004
      • 0 Attachment
        --- In perl-beginner@yahoogroups.com, "Irek Rybark" <irek@p...> wrote:
        > Hi!
        > I am new to perl and CGI. I am even not sure that this is
        > more perl or CGI problem.
        >
        > I am trying to use CSV module by Christopher Rath
        > http://rath.ca/Misc/Perl_CSV/index.shtml
        > to parse some comma separated file.
        > My problem is that my script is **not working on a server**,
        > however is **working on my local box** (W2k command prompt).
        >
        > This is an output on my box:
        > ================================================
        > C:\Perl\lib\CSV-2\Demo_App>perl CSV_test.cgi
        > Content-type: text/html
        > Item Number,Item Name,Item Description,Item Type
        > <p> J00E0001, Tirbal Necklace, Charming tribal necklace </p>
        > <p> J00T0001, Jade Necklace, Beautiful Chinese jade necklace </p>
        > ================================================
        >
        > This is an output from HTTP server: (you can see it with your own
        > eyes: http://sutherlandstudios.netfirms.com/cgi/cgierr.pl/cgi-
        > bin/CSV_test.cgi)
        > ================================================
        > Content-type: text/html Item Number,Item Name,Item Description,Item
        > Type Oups! Some fields are missing from the input file.end
        > ================================================
        > What could be wrong?
        > I appreciate any feedback,
        > Irek
        >
        >
        >
        > Perl version: 5.6.1 (local and the server)
        > Script to download: http://sutherlandstudios.netfirms.com/CSV_test.cgi
        >
        > Actually, suspecting some problems with calling functions from
        > external module I put test code into CGI module.
        >
        > Key part of the scrit follows:
        > ================================================
        > #!/usr/bin/perl -w
        > use strict;
        > print "Content-type: text/html\n";
        > $CSV::Delimiters = undef;
        > my(%CSVDefaultColumnMapping) = ("" => -1);
        >
        > my($ITEM_NUM) = "Item Number";
        > my($ITEM_NAME) = "Item Name";
        > my($ITEM_DESC) = "Item Description";
        > my($ITEM_TYPE) = "Item Type";
        >
        > my($input) = "items.csv"; #$ARGV[0];
        > my($item_type) = "NECKLACE"; #$ARGV[1];
        >
        > if (!open(INPUT, "$input")) {
        > die "$0: ERROR, cannot open input file, $input\n"
        > ."\tno data generated.\n";
        > } else {
        > my($firstLine) = scalar(<INPUT>);
        > my(%CSVfields) = CSVinit($firstLine);
        >
        > print$firstLine;
        >
        > if (! CSVvalidate(\%CSVfields, $ITEM_NUM, $ITEM_NAME, $ITEM_DESC,
        > $ITEM_TYPE)) {
        > # die "Some fields are missing from the input file.";
        > print "Oups! Some fields are missing from the input file.";
        > } else {
        > my(@record); # Where we'll store parsed records.
        > my($outrec); #Output record (a string).
        >
        > while (<INPUT>) {
        > @record = CSVsplit($_);
        > if ("\U$record[$CSVfields{$ITEM_TYPE}]"
        > eq "\U$item_type") {
        > printf "<p> %s, %s, %s </p>\n",
        > "$record[$CSVfields{$ITEM_NUM}]",
        > "$record[$CSVfields{$ITEM_NAME}]",
        > "$record[$CSVfields{$ITEM_DESC}]";
        > }
        > }
        > }
        > }
        > ##### THE REST HAS BEEN REMOVED

        So, it seems that CSVvalidate() is failing.
        One possibility - the input file was uploaded by ftp as binary instead
        of ascii? It might make (though shouldn't) make a difference.

        BTW, your Content-Type is html but you aren't providing '<html>'
        and '<body>' tags. Also,
        print "Content-type: text/html\n";
        should have two '\n'.
        I find the CGI module helpful for headers and other CGI functionality.
        You may not need it if your script is not responding to a form.

        Damien.
      • Irek Rybark
        Hello! Bull s-eye! I re-uploaded the file in text mode and it is working. Does it have something to do with CR/LF conversion? Thanks a lot for the hint! Btw,
        Message 3 of 4 , Aug 4, 2004
        • 0 Attachment
          Hello!
          Bull's-eye!
          I re-uploaded the file in text mode and it is working. Does it have
          something to do with CR/LF conversion?
          Thanks a lot for the hint!

          Btw, why
          > print "Content-type: text/html\n";
          > should have two '\n'.
          ?

          Irek

          --- In perl-beginner@yahoogroups.com, daymobrew@y... wrote:
          > --- In perl-beginner@yahoogroups.com, "Irek Rybark" <irek@p...>
          wrote:
          > > Hi!
          > > I am new to perl and CGI. I am even not sure that this is
          > > more perl or CGI problem.
          > >
          >..... CUT!

          > So, it seems that CSVvalidate() is failing.
          > One possibility - the input file was uploaded by ftp as binary
          instead
          > of ascii? It might make (though shouldn't) make a difference.
          >
          > BTW, your Content-Type is html but you aren't
          providing '<html>'
          > and '<body>' tags. Also,
          > print "Content-type: text/html\n";
          > should have two '\n'.
          > I find the CGI module helpful for headers and other CGI
          functionality.
          > You may not need it if your script is not responding to a form.
          >
          > Damien.
        • daymobrew@yahoo.com
          ... Yes ... Headers (and Content-type is one) always need a blank line before the data.
          Message 4 of 4 , Aug 5, 2004
          • 0 Attachment
            --- In perl-beginner@yahoogroups.com, "Irek Rybark" <irek@p...> wrote:
            > Hello!
            > Bull's-eye!
            > I re-uploaded the file in text mode and it is working. Does it have
            > something to do with CR/LF conversion?
            Yes

            > Btw, why
            > > print "Content-type: text/html\n";
            > > should have two '\n'.
            > ?
            Headers (and 'Content-type' is one) always need a blank line before
            the data.

            >
            > Irek
            >
            > --- In perl-beginner@yahoogroups.com, daymobrew@y... wrote:
            > > --- In perl-beginner@yahoogroups.com, "Irek Rybark" <irek@p...>
            > wrote:
            > > > Hi!
            > > > I am new to perl and CGI. I am even not sure that this is
            > > > more perl or CGI problem.
            > > >
            > >..... CUT!
            >
            > > So, it seems that CSVvalidate() is failing.
            > > One possibility - the input file was uploaded by ftp as binary
            > instead
            > > of ascii? It might make (though shouldn't) make a difference.
            > >
            > > BTW, your Content-Type is html but you aren't
            > providing '<html>'
            > > and '<body>' tags. Also,
            > > print "Content-type: text/html\n";
            > > should have two '\n'.
            > > I find the CGI module helpful for headers and other CGI
            > functionality.
            > > You may not need it if your script is not responding to a form.
            > >
            > > Damien.
          Your message has been successfully submitted and would be delivered to recipients shortly.