Spencer_Lists wrote:

> Greetings $Bill,
> 
> 
>>No excuse.  Format it properly, compile it using 'use strict;' and 'use 
>>warnings;'
>>till it has no errors (or produces the expected error) and then post it by
>>cutting and pasting into the email (from your text editor).  If you don't
>>have a good text editor, I would go out and get one and learn it if you
>>plan on doing any amount of coding (Vim and Emacs are free, multi-platform
>>and very good products).
> 
> 
> I have an editor that I think is pretty good (Optiperl) The problem is
> that when I paste it into the e-mail, the mail program (The Bat) makes
> a mess that can not be edited within the mail program. This is my only
> serious complaint about the bat and I am too committed to change
> programs. I did a lot of pre-editing to make it less of a mess. When I
> paste it in, it still messes up the indenting and I can not edit it
> without making a total mess.
> 
> The pasted code is part of a much larger program that uses MIDI perl.
> All variables are declared and have appropriate scope. I simplified
> the following a little. My only question is why the same assignments
> to an array work fine in one way and not the other. I had two lines
> swapped in the original example but I had tested both orders and they
> worked the same so I made them consistent in this example so as to not
> call attention to that as a possible difference. I would like to
> figure out what causes the problem so I can find a solution faster the
> next time something like this happens. I re-wrote the code about 20
> times before I tried moving the array assignment to another block. The
> various temporary arrays (on_off_time and note_array) are initialized
> and modified outside of the example shown and this all works as it
> should. To show what the program really does would require a very
> large example which would not make the problem clearer.Lists <[EMAIL 
> PROTECTED]>

I reformatted it for you, but it won't compile without errors and there's
too much code for a test case.  You need to trim it to the bare essentials
and run it both ways (bad and good) and show what's wrong with the bad one.

Do not submit it to the list without these two lines and a clean compile:
        use strict;
        use warnings;
which means you need to define all your vrbls in scope.

if ($dothis) {  # this works correctly

        my $shiftticks = 100;
        my $gapsize = $time - $on_off_time_array3[$note];

        if ($gapsize  < $mingapticks and $on_off_time_array1[$note] >= 0 ) {

                ++$smallgaps;
                $notelength = $on_off_time_array3[$note] -
                  $on_off_time_array2[$note];

                # if a short note would be made then shift instead
                if ($notelength - $shiftticks < $minnoteticks) {
                        ++$shortnotes;
                        # if room to shift
                        if ($on_off_time_array2[$note] -
                          $on_off_time_array1[$note] > i
                          $mingapticks + $shiftticks) {

                                my $newtime2 = $on_off_time_array3[$note] -
                                  $shiftticks;
                                $shifted = 1;

                                # shift the note on
                                my $newtime = $on_off_time_array2[$note] -
                                  $shiftticks;
                                $on_off_time_array2[$note] = $newtime;
                                # replacement previous off event
                                my @replace2 = ('note_on', $newtime, $channel,
                                  $note, $vel);
                                ${$tracks->[$i]->events_r}[$notearray2[$note]]
                                  = undef;
                                push @{$tracks->[$i]->events_r}, [EMAIL 
PROTECTED];
                        } else {
                                # could't shrink or shift - don't change events
                                $noroom = 1;
                                ++$nofixgaps;
                        }
                }
                $newtime = $time - $mingapticks;
                $newtime = $newtime2 if $shifted;
                # save temporarily so array1 will get the value before updating 
it
                $on_off_time_array3[$note] = $newtime;
                # replacement previous off event
                my @replace = ('note_on', $newtime, $channel, $note, 0);
                unless ($noroom) {
                        ${$tracks->[$i]->events_r}[$notearray3[$note]] = undef;
                        push @{$tracks->[$i]->events_r}, [EMAIL PROTECTED];
                }
        }
}

if ($dothis) {  # this version doesn't work

        my $shiftticks = 100;
        $gapsize = $time - ($on_off_time_array3[$note]);

        if ($gapsize  < $mingapticks and $on_off_time_array1[$note] >= 0) {
                ++$smallgaps;
                $notelength = $on_off_time_array3[$note] -
                  $on_off_time_array2[$note];
                # if a short note would be made then shift instead
                if ($notelength - $shiftticks < $minnoteticks) {
                        ++$shortnotes;
                        # if room to shift
                        if ($on_off_time_array2[$note] -
                          $on_off_time_array1[$note] >
                          $mingapticks + $shiftticks) {

                                # shift the note on
                                $newtime = $on_off_time_array2[$note] -
                                  $shiftticks;
                                $on_off_time_array2[$note] = $newtime;
                                # replacement previous off event
                                my @replace = ('note_on', $newtime, $channel,
                                  $note, $vel);
                                ${$tracks->[$i]->events_r}[$notearray2[$note]]
                                  = undef;
                                push @{$tracks->[$i]->events_r}, [EMAIL 
PROTECTED];

                                $newtime = $on_off_time_array3[$note] -
                                  $shiftticks;
                                $on_off_time_array2[$note] = $newtime;
                                # replacement previous off event
                                my @replace2 = ('note_on', $newtime, $channel,
                                  $note, 0);
                                ${$tracks->[$i]->events_r}[$notearray3[$note]]
                                  = undef;
                                push @{$tracks->[$i]->events_r}, [EMAIL 
PROTECTED];
                        } else {
                                $newtime = $time - $mingapticks;
                                $newtime = $newtime2 if $shifted;
                                $on_off_time_array3[$note] = $newtime;
                                # replacement previous off event
                                my @replace = ('note_on', $newtime, $channel,
                                  $note, 0);
                                ${$tracks->[$i]->events_r}[$notearray3[$note]]
                                  = undef;
                                push @{$tracks->[$i]->events_r}, [EMAIL 
PROTECTED];
                        }
                }
        }
}

__END__


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to