Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: An Elegance Question

by plaid (Chaplain)
on Apr 13, 2000 at 23:02 UTC ( #7512=note: print w/ replies, xml ) Need Help??


in reply to An Elegance Question

Another interesting way. This will take anything in [], and prompt for a word of that type. This eliminates the need to hard-code adjectives, adverbs, nouns, etc. Your file can look like

The [noun] [past-tense verb] over to [proper noun] and soon [future-tense verb] to the [place].
This allows you more flexibility in what you want them to input
!/usr/bin/perl -w use strict; my $story; { local $/ = undef; #Get everything $story = <>; } while($story =~ /\[(.*?)\]/g) { #Find anything in [] print "Give me a $1: "; my $val = <STDIN>; #Get a value for it chomp $val; $story =~ s/\[$1\]/$val/; #And sub it in } print $story;


Comment on Re: An Elegance Question
Select or Download Code
RE: Re: An Elegance Question
by Simplicus (Monk) on Apr 13, 2000 at 23:07 UTC
    This is truly awe inspiring. I need to go be alone for a while. I am humbled, and my coffee cup is empty. Simplicus.
RE: Re: An Elegance Question
by Simplicus (Monk) on Apr 13, 2000 at 23:34 UTC
    I just tried this, and it works (of course) . . .what impresses me about this solution is not only its brevity, but its clarity. Simplicus.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://7512]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2015-07-02 01:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls