Dennis Warren wrote:
>
> Hi,
Hello,
> I'm trying to use data to work out the average durations of certain sounds
> for a project here at work. The problem I have is that I'm a real newbie at
> Perl, and I'm finding the data really hard to get my head around. I don't
> really know where to begin. Any suggestions for an approach would be really
> appreciated.
>
> The data, in plain text files, looks something like this:
>
> 1.40616 tw-
> 1.51162
> 1.53491 w-ih
> 1.55572
> 1.61759 ihLx
> 1.70433
> 1.74422 Lx#
> 1.91998
> 1.94224 UU
> 1.95236
>
> The first column is a time in seconds, and the second column (not always
> filled) represents the symbol/sound I'm measuring.
>
> What I need to do is to work out the length of a certain symbol. (the one in
> the 2nd column, e.g. "w-ih"). I have to do this by taking the time in the
> previous record away from the time in the next record to get the duration
>
> 1.40616 tw-
> 1.51162 <- the start time of the symbol to measure
> 1.53491 w-ih <- the symbol to measure
> e.g. 1.5572 - 1.51162 = 0.04558
> 1.55572 <- the stop time of the symbol to measure
> 1.61759 ihLx
> 1.70433
>
> As you can see, the stop time for one sound is very often also the start
> time for the next sound. As well as this I face the problem that the first
> sound in all the records cannot be measured, as it has no start point. So I
> must always ignore this. I want to output the durations of all the symbols
> in a given data set, e.g..
>
> w-ih 0.04558
> ihLx 0.14861
>
> Any solutions, or hints at achieving a solution would be great
my ( $prev, $symbol );
while ( <> ) {
my @data = split;
if ( @data == 1 ) {
print "$symbol ",$data[0]-$prev,"\n" if defined $prev;
$prev = $data[0];
}
elsif ( @data == 2 ) {
$symbol = $data[1];
}
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]