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

Re: Print %myfile is reordering the rows of my file. Why?

Expand Messages
  • coo_t2@yahoo.com
    Right now you re using a hash to store the file. Try using a regular array. use cgi; use strict; my $p = new CGI; print start_html; print $p- header; open
    Message 1 of 2 , Dec 3, 2001
    • 0 Attachment
      Right now you're using a hash to store the file.
      Try using a regular array.

      use cgi;
      use strict;
      my $p = new CGI;
      print start_html;
      print $p->header;
      open MYFILE, 'tempo.pm' or die 'cannot open tempo.pm';
      my @myfile = <MYFILE>; #changed (%)hash to (@)array
      print @myfile; #print array
      print end_html;

      --------------------------

      --- In perl-beginner@y..., jonathan.mark2@d... wrote:
      > I have a file called tempo.pm that consists of:
      >
      > row 1
      > row 2
      > row 3
      > row 4
      > row 5
      >
      > I have the following CGI script that opens, reads and prints it:
      >
      > use cgi;
      > use strict;
      > my $p = new CGI;
      > print start_html;
      > print $p->header;
      > open MYFILE, 'tempo.pm' or die 'cannot open tempo.pm';
      > my %myfile = <MYFILE>;
      > print %myfile;
      > print end_html;
      >
      >
      > However, when I run the script on the file the result is:
      >
      > row 3
      > row 4
      > row 5
      > row 1
      > row 2
      >
      > Does anyone know the reason why the script is reordering the file?
      It
      > makes no sense.
    Your message has been successfully submitted and would be delivered to recipients shortly.