As you can see, the script reads in a story from a file, and replaces up to three instances of nouns, verbs, and adjectives. The problem is that the method is grossly inelegant. I know there must be a less brutish solution, so I turn to you for guidance. Thanks#!/usr/bin/perl -w @story = <>; #filename supplied in ARGV print "give me a noun: "; chomp($noun1 = <STDIN>); print "give me a noun: "; chomp($noun2 = <STDIN>); print "give me a noun: "; chomp($noun3 = <STDIN>); print "give me a verb: "; chomp($verb1 = <STDIN>); print "give me a verb: "; chomp($verb2 = <STDIN>); print "give me a verb: "; chomp($verb3 = <STDIN>); print "give me an adjective: "; chomp($adj1 = <STDIN>); print "give me an adjective: "; chomp($adj2 = <STDIN>); print "give me an adjective: "; chomp($adj3 = <STDIN>); foreach (@story) { $_ =~ s/\[noun1\]/$noun1/g; $_ =~ s/\[noun2\]/$noun2/g; $_ =~ s/\[noun3\]/$noun3/g; $_ =~ s/\[verb1\]/$verb1/g; $_ =~ s/\[verb2\]/$verb2/g; $_ =~ s/\[verb3\]/$verb3/g; $_ =~ s/\[adj1\]/$adj1/g; $_ =~ s/\[adj2\]/$adj2/g; $_ =~ s/\[adj3\]/$adj3/g; print $_; }
In reply to An Elegance Question by Simplicus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |