Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Use of uninitialized value $file in concatenation

by Anonymous Monk
on Sep 30, 2013 at 18:38 UTC ( [id://1056405]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

use strict; opendir(DIR, "./") or die $!; # open current directory my @files; while (my $file = readdir(DIR)) { # Use a regular expression to ignore files beginning with a period push(@files, lc($file)); } closedir(DIR); # read the prompt. my $promptfile = shift; print STDERR "reading $promptfile\n"; open(PROMPT, $promptfile); my $i = 0; while (my $prompt = <PROMPT>) { $i++; print STDERR $prompt . "\n"; $prompt =~ s/^\d+\.\s//; # remove "93. "; $prompt = lc($prompt); # concat a list of .wav files corresponding to the prompt my $files = ""; foreach my $word (split(/\s+/, $prompt)) { # choose a random file from the files, that beings with the gi +ven $word. my @grepped = grep(/^$word/, @files); my $file = $grepped[ int(rand(scalar @grepped)) ]; # choose a +random file $files .= $file . " "; } my $output = sprintf("S%05d",$i); my $command = "sox $files $output.wav"; print STDERR $command . "\n"; # TODO: add system call. system($command); print STDOUT "$output.wav $output.mfc\n"; } close(PROMPT);

AFTER RUN THIS I GOT

Use of uninitialized value $file in concatenation (.) or string at scr +ipts/conca tprompt.pl line 29, <PROMPT> line 100. sox S00100.wav sox FAIL sox: Not enough input filenames specified

AND COMMAND IS LIKE:

perl -w scripts/concatprompt.pl trainprompts > codetrain.scp

PLEASE TELL ME HOW TO REMOVE THIS ERROR...

Replies are listed 'Best First'.
Re: Use of uninitialized value $file in concatenation
by toolic (Bishop) on Sep 30, 2013 at 19:06 UTC
Re: Use of uninitialized value $file in concatenation
by chromatic (Archbishop) on Sep 30, 2013 at 21:27 UTC
Re: Use of uninitialized value $file in concatenation
by aaron_baugher (Curate) on Sep 30, 2013 at 21:55 UTC

    Are you seeing what you expect when you print $prompt and $promptfile to STDERR? If not, figure out why. (One hint: you probably want to chomp your lines from your input file. A trailing newline will mess up the last filename on the line, at least.) If those are okay, put similar print statements inside your foreach loop to print variables like $word and $file, to see when you stop getting the results you expect.

    Aaron B.
    Available for small or large Perl jobs; see my home node.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1056405]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found