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

Re: [PBML] reading two files from while loop

Expand Messages
  • Joe
    Doesnt matter. Preferably Null. But either way is ok with me. ... loop ... I ... file ... anybody ... you want for ... value
    Message 1 of 4 , Jun 2, 2003
    • 0 Attachment
      Doesnt matter. Preferably Null. But either way is ok with me.

      --- In perl-beginner@yahoogroups.com, "Jonathan Dunn" <jon@e...>
      wrote:
      > On Tue, 03 Jun 2003 01:00:30 -0000, Joe wrote
      > > What if I wanted to read from two files, and wanted the while
      loop
      > > to continue during the length of the LONGEST file. For example,
      > >
      > > while (defined($Gold = <GOLD> && $Test = <TEST>){
      > >
      > > print "$Test" unless $Test eq $Gold;
      > >
      > > }
      > >
      > > will do the comparison until the shortest file is finished. But
      I
      > > want it to do it until the longest file is finished. If I change
      > > the && to an OR, it will only read in the line from the FIRST
      file
      > > ($Gold). It wont even bother reading in the $Test line. Can
      anybody
      > > come up with any other suggestions?
      >
      > If you're still reading from the longer file, then what value do
      you want for
      > the variable which was being read from the shorter file? the last
      value
      > read? null?
    • Jonathan Dunn
      On Tue, 03 Jun 2003 01:13:35 -0000, Joe wrote ... Hows this: ### script #!/usr/local/bin/perl use CGI qw( :standard ) ; use CGI::Carp qw( fatalsToBrowser ) ;
      Message 2 of 4 , Jun 2, 2003
      • 0 Attachment
        On Tue, 03 Jun 2003 01:13:35 -0000, Joe wrote
        > Doesnt matter. Preferably Null. But either way is ok with me.
        Hows this:

        ### script

        #!/usr/local/bin/perl

        use CGI qw( :standard ) ;
        use CGI::Carp qw( fatalsToBrowser ) ;
        use strict ;

        my ( $category, %info ) ;

        print header ;
        print start_html ;
        print "<pre>\n" ;

        open( TEST, "<file.txt" ) ;
        open( GOLD, "<gold.txt" ) ;

        print "Starting\n" ;

        while (1) {
        my $Gold = <GOLD> ;
        my $Test = <TEST> ;
        if( defined($Gold) || defined($Test) ) {
        if ( $Test eq $Gold ) {
        # ok
        } else {
        my $string = "Test:$Test , Gold:$Gold" ;
        $string =~ s#\n##g ;
        print "$string\n" ;
        }
        } else {
        last ;
        }
        }

        print "Finished\n" ;
        print end_html ;
        close ;
        exit ;
      Your message has been successfully submitted and would be delivered to recipients shortly.