Perl Code Written In Windows not working on Linux

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • group8perl
    New Member
    • Feb 2007
    • 13

    Perl Code Written In Windows not working on Linux

    I have this perl code written using Notepad which works fine using Apache but when i try to run the perl script on a Linix browser i get a program/script failure error.
    Can someone please help me understand why this error is occuring

    Code:
    #!/usr/bin/perl
    
    $filename = "ROOMS2.txt";
    open(FILE, "$filename") || die("Unable to open $filename: $!\n");
    
    @theRest = <FILE>;
    close(FILE);
    
    print "content-type: text/html\n\n";
    print"@theRest";
    print "<table border='1'>";
    
    foreach $line (@theRest) {
    	($loc,$size,$code)=split(/\|/,$line);
    	print "<tr><td>$loc</td><td>$size</td><td>$code</td></tr>";
    }
    print"</table>";
    Thank You
    Last edited by miller; Feb 27 '07, 05:52 PM. Reason: Code tag
  • docsnyder
    New Member
    • Dec 2006
    • 88

    #2
    Originally posted by group8perl
    I have this perl code written using Notepad which works fine using Apache but when i try to run the perl script on a Linix browser i get a program/script failure error.
    Can someone please help me understand why this error is occuring

    #!/usr/bin/perl

    $filename = "ROOMS2.txt ";
    open(FILE, "$filename" ) || die("Unable to open $filename: $!\n");

    @theRest = <FILE>;
    close(FILE);

    print "content-type: text/html\n\n";
    print"@theRest" ;
    print "<table border='1'>";

    foreach $line (@theRest) {
    ($loc,$size,$co de)=split(/\|/,$line);
    print "<tr><td>$l oc</td><td>$size</td><td>$code</td></tr>";
    }
    print"</table>";

    Thank You
    Did you remove the <CR> character?

    dos2unix may help, but there are other possibility, like vi, etc.

    Greetz, Doc

    Comment

    • group8perl
      New Member
      • Feb 2007
      • 13

      #3
      Thanks for the quick reply
      All i did was copy the entire code and paste it in a new file using evim. Then it managed to work.

      Comment

      • group8perl
        New Member
        • Feb 2007
        • 13

        #4
        Another question based on the same code
        How do i change the font for the tables and add background colours to the cells
        Is it similar to HTML code
        Thank You

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Your code is not well thought out, you have a die command before the http header is printed. If the script dies and tries to print an error message to STDOUT it will bomb with a 500 internal server error. Use:

          use CGI::Carp qw/fatalsToBrowser/;

          at the beginning (just after the path to perl line) while debugging CGI scripts.It will print a header and allow you to see the value of $!. If you still get a 500 error the problem is that the perl code can't even be interpreted properly, ie: shebang line is wrong, uploaded in binary format, or possibly wrong permissions.

          Comment

          • group8perl
            New Member
            • Feb 2007
            • 13

            #6
            This was just an attempt to get some practice with Perl
            In most of my perl scripts i have used

            use CGI::Carp 'fatalsToBrowse r';

            Comment

            • KevinADC
              Recognized Expert Specialist
              • Jan 2007
              • 4092

              #7
              Originally posted by group8perl
              Another question based on the same code
              How do i change the font for the tables and add background colours to the cells
              Is it similar to HTML code
              Thank You
              It's not similar to html code, it is html code. Just add html code like you would to any html document. If you need dynamic changes then you would use perl to alter a variable and insert it into the html code as needed before the html code is printed to STDOUT/the browser.

              Comment

              • vpmurdan
                New Member
                • Feb 2007
                • 25

                #8
                Hi!
                A very dumb reply from me.

                In linux, is the name of your file 'ROOMS2.txt' using the same case?

                Linux is case sensitive.

                Comment

                Working...