Open (IN...) command failing possibly due to problems with naming

67 Views Asked by At

New to Perl and quite new to coding in general so I apologise if this is formatted terribly and an easy question! Trying simply to input somebody's elses code as a step in a larger project involving PRAAT. The code is designed to distinguish beats in speech rhythm, I've followed their nomenclature in file naming (on line 2) but the code won't move past line 13. Could anyone tell me why? Is it trying to open a directory called "intensities"? Additionally, is there anywhere else I may have to change the code, it is quite possibly reasonably old! Thank you very much!

#!/usr/local/bin/perl -w
scalar(@ARGV) == 1 or scalar(@ARGV) == 2 or die "Usage: getBeatsOneShot.pl someSoundFile <threshold>";
$stem = shift;

# Parameters to fiddle with
if (scalar(@ARGV) == 0) {
  $threshold = 0.2;
} else {
  $threshold = shift;
  print "Threshold is $threshold\n";
}

open(IN, "intensities/$stem.intensity") or die "badly";
open(OUT, ">beats/$stem.beats")  or die "eek";

# File type = "ooTextFile short"
$_ = <IN>; print OUT $_;

# replace "Intensity" with "TextGrid"
$_ = <IN>; print OUT "\"TextGrid\"\n\n";

# skip a line
$_ = <IN>;

chomp($xmin = <IN>);
chomp($xmax = <IN>);
chomp($nx = <IN>);  $nx = 0; #(just suprress a arning here)
chomp($dx = <IN>);
chomp($x1 = <IN>);

# Read in intensity contour into @e (envelope)
@e = ();
while($_ = <IN>) { chomp; last unless $_ eq "1";}
push @e, $_;

while($_ = <IN>) {
  chomp($_);
  push @e, $_;
}


# (1) Find max and min
$max = 0; $min = 1000000;
foreach $ival (@e) {
  if($ival > $max) {
    $max = $ival;
  }
  if($ival < $min) {
    $min = $ival;
  }
}

# (2) look for beats
@beats = ();

print "Thresh: $threshold\n";
1

There are 1 best solutions below

1
choroba On

open doesn't create the path to the file. Directories intensities/ and beats/ therefore must exist in the current working directory before the script is run.

When open fails, it sets $! to the reason of the failure. Instead of eek or badly, use die $! so Perl can tell you what went wrong.

Moreover, you should turn strict and warnings on. They prevent many common mistakes. As a newbie, you might like to enable diagnostics, too, to get detailed explanations of all the errors and warnings.