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

Re: [PBML] Do I need an inner loop or ?

Expand Messages
  • Jonathan Mangin
    It s true enough, I have a hard time asking questions properly owing to wide and deep ignorance. I include a snippet of table only to show normalized
    Message 1 of 7 , Dec 5, 2005
    • 0 Attachment
      It's true enough, I have a hard time asking questions
      properly owing to wide and deep ignorance. I include
      a snippet of table only to show "normalized" nature.
      Many more columns from three similar tables are involved.
      Poor example data:

      | 4 | 2005-08-01 | 15:00:00 | S | .005 | 72 |
      | 5 | 2005-08-01 | 18:32:00 | S | .008 | 144 |
      | 6 | 2005-08-01 | 21:37:00 | S | .007 | 114 |
      | 7 | 2005-08-02 | 04:00:00 | O | | 94 |
      | 8 | 2005-08-02 | 06:09:00 | S | .006 | 91 |
      | 9 | 2005-08-02 | 07:31:00 | S | .008 | 128 |

      my $date1 = Date::Simple->new($bdate);
      # my $date2 = Date::Simple->new($edate);

      # Been moved many times. You'd be yucky too. (Helps prove reality :)
      my %vals = ();
      my @temp = ();
      my @data = ();
      while (my @row = $sth->fetchrow_array) {

      # Compare date
      if ($row[0] eq $date1) {

      # Phantom $row[6] is time column in HHMM format
      $vals{$row[6]} = [substr($row[1],0,5), $row[3], $row[4], $row[5]];

      # If true...
      # $vals{1500} = [15:00, S, .005, 72]

      next;

      # If still true...
      # $vals{1832} = [18:32, S, .008, 144]
      # $vals{2137} = [21:37, S, .007, 114]
      }


      # Moved for clarity(?)
      @temp = ($row[0], \%vals);
      # @temp = ('2005-08-01', \%vals);
      push @data, [@temp];

      # (%vals, @temp) = ();
      $date1 = $date1->next;
      }

      Now go back and do it all again for 2005-08-02 and subsequent days
      resulting in @data = [@temp, @temp, @temp...]

      Don't understand much of the following though you seem know
      approximately what I need. Does using the time as key change
      appreciably what you've done?

      > my %data_by_date;
      > while ( my( $date, $time, @record ) = $sth->fetchrow_array() ) {
      > push @{ $data_by_date{ $date } }, [ substr($time, 0, 5), @record ];
      > }
      >
      > my $date1 = Date::Simple->new($bdate);
      > $data_by_date{ $date1 } will now return an array of arrays.
      >
      > : @temp = ($row[0], \%vals);
      >
      > This resets @temp each time through. All previous values will
      > be lost.
      >
      >
      > : next;
      > : }
      >
      > YMMV, but I prefer "else" to "next" in this situation. I think
      > it gives a better hint to what is happening.
      >
      >
      > if ( $row[0] eq $date1 ) {
      > $vals{ $row[6] } = [ substr($row[1],0,5), $row[3], $row[4], $row[5]
      > ];
      > @temp = ( $row[0], \%vals );
      >
      > } else {
      > push @data, [@temp];
      > $date1 = $date1->next;
      > }
      >
      >
      > HTH,
      >
      > Charles K. Clarkson
      > --
      > Mobile Homes Specialist
      > 254 968-8328
      >
      Charles,
      I wonder if you can put it all together in one piece for me
      to study? Thanks for the time you've given me already.

      --Jon
    • Charles K. Clarkson
      ... You can become less ignorant by learning. Many of traits needed for asking good questions are also the traits needed to be a good programmer.
      Message 2 of 7 , Dec 5, 2005
      • 0 Attachment
        Jonathan Mangin <> wrote:

        : It's true enough, I have a hard time asking questions properly
        : owing to wide and deep ignorance.

        You can become less ignorant by learning. Many of traits
        needed for asking good questions are also the traits needed to be
        a good programmer.

        http://www.catb.org/~esr/faqs/smart-questions.html


        : I include a snippet of table only to show "normalized" nature.
        : Many more columns from three similar tables are involved.

        Then show us the columns actually returned or stick to just
        the six columns in your example code. This was one problem Randal
        had with your code. You referred to the seventh column ($row[6])
        with only 6 columns (@row[0..5]) in the example code.

        Tell us what you want in clear concise terms. Forget all the
        variables, just show us what the data structure is suppose to look
        like by using the data in a table of supplied data.


        HTH,

        Charles K. Clarkson
        --
        Mobile Homes Specialist
        254 968-8328
      Your message has been successfully submitted and would be delivered to recipients shortly.