So I'm being asked to generate a fairly large number of small text files (about 1 sentence long). The words can be the same every time, but each sentence has to contain a different bunch of numbers. It would look a bit like this:

"The lucky numbers of the day are _1, _2, _3, _4, _5 and don't forget to play again next week."
The aim of this is to test the performance of a recently developed text to speech synthesizer.

Anyway, this is what I've come up with so far (with some help from a friend). It kind of works a bit anyway (well the 2 number generator works, I'm still 'debugging' a.k.a. 'fixing my bad code' on the 5 number generator). I'd appreciate it if the monks have any suggestions for me.

use strict; my $sentence_file = shift (@ARGV); my $numbers_file = shift (@ARGV); open SENTENCE, "$sentence_file" || die "cannot open $sentence_file for + reading: $!"; open NUMBERS, "$numbers_file" || die "cannot open $numbers_file for re +ading: $!"; my $sentence = (<SENTENCE>)[0]; print "sentence: $sentence\n"; my @numbers = <NUMBERS>; foreach my $number (@numbers) { my $working_sentence = $sentence; chomp $number; $number =~ s/\.$//g; my $output_file; if ($working_sentence =~ /_5/) { my $second_number = shift @numbers; my $third_number = shift @numbers; my $fourth_number = shift @numbers; my $fifth_number = shift @numbers; $working_sentence =~ s/_5/$number $second_number $third_number $four +th_number $fifth_number/; $output_file = "number.test5.".$number."_".$fifth_number.".txt"; } elsif ($working_sentence =~ /_2/) { my $second_number = shift @numbers; $working_sentence =~ s/_2/$number $second_number/; $output_file = "number.test2.".$number."_".$second_number.".txt"; } open OUTPUT, ">$output_file" || die "cannot open $output_file for wr +iting: $!"; print OUTPUT $working_sentence."\n"; close OUTPUT; }

I'm sorry - this could be formatted better, (and be a less stupid question) I'm still feeling my way a bit...ok, a lot! :p

'share and enjoy'

In reply to sentence generation by Ella

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.