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

Re: [PBML] Problems opening a txt file for reading

Expand Messages
  • Mike Southern
    ... You need to escape the directory slashes in the path: open (TXTFILE, c: Program Files iLinc Server Web Test CLASS.TXT ); But after that you don t
    Message 1 of 12 , Oct 5, 2006
      On 10/5/06 12:14 PM, chipwillis2003 at chipwillis2003@... wrote:

      > #!/usr/bin/perl -wT
      >
      > $name = 'chip';
      > print "Hello, $name!\n";
      >
      >
      > Next I try to open a text file but this does not work.
      >
      > #!/usr/bin/perl -wT
      >
      > open (TXTFILE, "c:\Program Files\iLinc\Server\Web\Test\CLASS.TXT");
      > @lines = <TXTFILE>;
      > close(TXTFILE);
      >
      > All the file extensions are .pl
      >
      > The text file is there and does not have any attributes set.
      > What am I not doing?

      You need to escape the directory slashes in the path:

      open (TXTFILE, "c:\\Program Files\\iLinc\\Server\\Web\\Test\\CLASS.TXT");

      But after that you don't say how you know that the file doesn't open.

      You've assigned the content to @lines, but what do you do next? I.E. What is
      the next bit of code that you haven't supplied here ...
    • merlyn@stonehenge.com
      ... Mike You need to escape the directory slashes in the path: Mike open (TXTFILE, c: Program Files iLinc Server Web Test CLASS.TXT ); or just use
      Message 2 of 12 , Oct 5, 2006
        >>>>> "Mike" == Mike Southern <gb1198@...> writes:

        Mike> You need to escape the directory slashes in the path:

        Mike> open (TXTFILE, "c:\\Program Files\\iLinc\\Server\\Web\\Test\\CLASS.TXT");

        or just use forward slashes:

        c:/Program Files/iLinc ...

        I don't know why everyone is so addicted to the backslashes. :)

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      • Mike Southern
        ... Habit. Like learning to drive a truck is largely eliminating bad car driving habits, so learning to write real software is elminiating all the bad things
        Message 3 of 12 , Oct 5, 2006
          On 10/5/06 3:48 PM, Randal L. Schwartz at merlyn@... wrote:

          > or just use forward slashes:
          >
          > c:/Program Files/iLinc ...
          >
          > I don't know why everyone is so addicted to the backslashes. :)

          Habit.

          Like learning to drive a truck is largely eliminating bad car driving
          habits, so learning to write real software is elminiating all the bad things
          we used to do in DOS ...
        • chip willis
          Forward slashes are fine with me. I do nothing at the moment with the txt file. I will after opening it split it into an array. The only thing in the txt file
          Message 4 of 12 , Oct 5, 2006
            Forward slashes are fine with me.
            I do nothing at the moment with the txt file. I will after opening it split it into an array. The only thing in the txt file at the moment is (without quotes) "this is a test".

            What needs to be done is to take the txt file which is a CSV file (comma delimited file), read it into an array and then take what I want out of the array and send it in XML to some API functions that ilinc (the software vender) has written which will create classes and register students into the classes and the instructor. Also create instructors and change network settings and so forth. I do this now with the ASP code but did not need to use the XML. I am just trying to do one thing (no so simple for me obviously) at a time. The CVS file is an exported file from PeopleSoft (software which the classes are originally input in here at the university) and import them into the ilinc software. iLinc is all web based distance learning software and has other prices for staff etc.

            So even if I try this:

            #!/usr/bin/perl -wT

            open (TXTFILE, "c:/Program Files/iLinc/Server/Web/Test/CLASS.TXT");
            #@lines = <TXTFILE>;
            #close(TXTFILE);

            I get the error on the web page that “The page can not be displayed” which means there is some error while trying to open the file.
            Is there a good Perl editor to use that will give me better error handling messages? I have tried DzSoft Perl Editor but it does not seem to work well with web pages or I have not figured it out yet.
            Thanks for your help,
            Chip



            Mike Southern <gb1198@...> wrote:
            On 10/5/06 12:14 PM, chipwillis2003 at chipwillis2003@... wrote:

            > #!/usr/bin/perl -wT
            >
            > $name = 'chip';
            > print "Hello, $name!\n";
            >
            >
            > Next I try to open a text file but this does not work.
            >
            > #!/usr/bin/perl -wT
            >
            > open (TXTFILE, "c:\Program Files\iLinc\Server\Web\Test\CLASS.TXT");
            > @lines = <TXTFILE>;
            > close(TXTFILE);
            >
            > All the file extensions are .pl
            >
            > The text file is there and does not have any attributes set.
            > What am I not doing?

            You need to escape the directory slashes in the path:

            open (TXTFILE, "c:\\Program Files\\iLinc\\Server\\Web\\Test\\CLASS.TXT");

            But after that you don't say how you know that the file doesn't open.

            You've assigned the content to @lines, but what do you do next? I.E. What is
            the next bit of code that you haven't supplied here ...






            ---------------------------------
            Get your own web address for just $1.99/1st yr. We'll help. Yahoo! Small Business.

            [Non-text portions of this message have been removed]
          • Mike Southern
            ... But you aren t performing any function on the contents of the file yet. You have just opened it and assigned it to an array. You then need to work on the
            Message 5 of 12 , Oct 5, 2006
              On 10/5/06 5:31 PM, chip willis at chipwillis2003@... wrote:

              > open (TXTFILE, "c:/Program Files/iLinc/Server/Web/Test/CLASS.TXT");
              > #@lines = <TXTFILE>;
              > #close(TXTFILE);
              >
              > I get the error on the web page that ³The page can not be displayed² which
              > means there is some error while trying to open the file.

              But you aren't performing any function on the contents of the file yet. You
              have just opened it and assigned it to an array.

              You then need to work on the contents of that array and present them to your
              end product - in this case a web page.

              so:

              Open file
              Assign file contents to array
              Close file

              For each record (line) of the array {
              print the line
              } #end the loop

              For example:

              foreach $line(@lines) {
              print "$line\n";
              }

              In reality you would use CGI to format that print line for HTML but the end
              result for each line could be

              print "<p>$line</p>";
            • ashish_gupta_cal
              Also try checking if file got successfully opened. It might help. open (TXTFILE, c:/Program Files/iLinc/Server/Web/Test/CLASS.TXT ) or die Cant open file :
              Message 6 of 12 , Oct 5, 2006
                Also try checking if file got successfully opened. It might help.

                open (TXTFILE, "c:/Program Files/iLinc/Server/Web/Test/CLASS.TXT") or
                die "Cant open file : $!";

                Regards,
                Ashish

                --- In perl-beginner@yahoogroups.com, Mike Southern <gb1198@...> wrote:
                >
                > On 10/5/06 5:31 PM, chip willis at chipwillis2003@... wrote:
                >
                > > open (TXTFILE, "c:/Program Files/iLinc/Server/Web/Test/CLASS.TXT");
                > > #@lines = <TXTFILE>;
                > > #close(TXTFILE);
                > >
                > > I get the error on the web page that ³The page can not be
                displayed² which
                > > means there is some error while trying to open the file.
                >
                > But you aren't performing any function on the contents of the file
                yet. You
                > have just opened it and assigned it to an array.
                >
                > You then need to work on the contents of that array and present them
                to your
                > end product - in this case a web page.
                >
                > so:
                >
                > Open file
                > Assign file contents to array
                > Close file
                >
                > For each record (line) of the array {
                > print the line
                > } #end the loop
                >
                > For example:
                >
                > foreach $line(@lines) {
                > print "$line\n";
                > }
                >
                > In reality you would use CGI to format that print line for HTML but
                the end
                > result for each line could be
                >
                > print "<p>$line</p>";
                >
              • chip willis
                Yes, adding this line works great: foreach $line(@lines) { print $line n ; } Seems without doing anything with the file caused the error. Thanks, Chip Mike
                Message 7 of 12 , Oct 5, 2006
                  Yes, adding this line works great:

                  foreach $line(@lines) {
                  print "$line\n";
                  }

                  Seems without doing anything with the file caused the error.
                  Thanks,
                  Chip

                  Mike Southern <gb1198@...> wrote:
                  On 10/5/06 5:31 PM, chip willis at chipwillis2003@... wrote:

                  > open (TXTFILE, "c:/Program Files/iLinc/Server/Web/Test/CLASS.TXT");
                  > #@lines = <TXTFILE>;
                  > #close(TXTFILE);
                  >
                  > I get the error on the web page that ³The page can not be displayed² which
                  > means there is some error while trying to open the file.

                  But you aren't performing any function on the contents of the file yet. You
                  have just opened it and assigned it to an array.

                  You then need to work on the contents of that array and present them to your
                  end product - in this case a web page.

                  so:

                  Open file
                  Assign file contents to array
                  Close file

                  For each record (line) of the array {
                  print the line
                  } #end the loop

                  For example:

                  foreach $line(@lines) {
                  print "$line\n";
                  }

                  In reality you would use CGI to format that print line for HTML but the end
                  result for each line could be

                  print "<p>$line</p>";






                  ---------------------------------
                  Stay in the know. Pulse on the new Yahoo.com. Check it out.

                  [Non-text portions of this message have been removed]
                • Mike Southern
                  ... I don t think there was really an error - you were assuming that just by opening the file a process would automatically do something with the content.
                  Message 8 of 12 , Oct 5, 2006
                    On 10/5/06 6:49 PM, chip willis at chipwillis2003@... wrote:

                    > Yes, adding this line works great:
                    >
                    > foreach $line(@lines) {
                    > print "$line\n";
                    > }
                    >
                    > Seems without doing anything with the file caused the error.
                    > Thanks,
                    > Chip

                    I don't think there was really an error - you were assuming that just by
                    opening the file a "process" would automatically do something with the
                    content.

                    And in a more detailed reality, the above "print" example may not work the
                    way you expect when you serve it to a HTML browser.

                    Each data component that you wish to display has to be formatted using HTML
                    as if you were writing the HTML content by hand, including the required
                    document tags.

                    Thus your work may start to look like this:

                    print "<html>";
                    print "<head>";
                    print "<title>Page title</title>";
                    print "</head>";
                    print "<body>";


                    foreach $line(@lines) {
                    print "<p>$line</p>";
                    }

                    print "</body>";
                    print "</html>";

                    But DON'T do that ... read about, and use, CGI.pm instead as it will save
                    you a ton of time spent formatting HTML.
                  • chip willis
                    Thanks for the info. What I will be doing is putting the contents of the txt file, a comma delimited file into a Windows SQL database using the venders suplied
                    Message 9 of 12 , Oct 8, 2006
                      Thanks for the info.
                      What I will be doing is putting the contents of the txt file, a comma delimited file into a Windows SQL database using the venders suplied API. So there will not need to be any HTML formating. I will no doubt need to learn that also with GGI.pm
                      Thanks
                      Chip

                      Mike Southern <gb1198@...> wrote:
                      On 10/5/06 6:49 PM, chip willis at chipwillis2003@... wrote:

                      > Yes, adding this line works great:
                      >
                      > foreach $line(@lines) {
                      > print "$line\n";
                      > }
                      >
                      > Seems without doing anything with the file caused the error.
                      > Thanks,
                      > Chip

                      I don't think there was really an error - you were assuming that just by
                      opening the file a "process" would automatically do something with the
                      content.

                      And in a more detailed reality, the above "print" example may not work the
                      way you expect when you serve it to a HTML browser.

                      Each data component that you wish to display has to be formatted using HTML
                      as if you were writing the HTML content by hand, including the required
                      document tags.

                      Thus your work may start to look like this:

                      print "<html>";
                      print "<head>";
                      print "<title>Page title</title>";
                      print "</head>";
                      print "<body>";

                      foreach $line(@lines) {
                      print "<p>$line</p>";
                      }

                      print "</body>";
                      print "</html>";

                      But DON'T do that ... read about, and use, CGI.pm instead as it will save
                      you a ton of time spent formatting HTML.






                      ---------------------------------
                      Do you Yahoo!?
                      Everyone is raving about the all-new Yahoo! Mail.

                      [Non-text portions of this message have been removed]
                    Your message has been successfully submitted and would be delivered to recipients shortly.