Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Sure, use Text::Template. You'll need to slightly change the format of your madlib. Instead of something like
the [noun1] [verb2]
you need to use
the [$noun1] [$verb2]
But that's not a big change. So you may need to change the script around a bit, but it should work pretty much as is.
use Text::Template; # read in the story my @story = <>; my $hash = { }; # these are the word types that you're # going to prompt for and include in your madlib; # the key is what you call the type in the madlib ("adj") # and the value is what you want to prompt for my %types = ( noun => 'noun', verb => 'verb', adj => 'adjective' ); # read in the values from STDIN; # you may want to change this around. # 3 means read 3 words of each type (3 nouns, 3 verbs, etc.) for my $type (keys %types) { for my $i (1..3) { print "give me a $types{$type}: "; chomp($hash->{$type . $i} = <STDIN>); } } # set up a new template object: # get template from array @story where template # variables are in [] (DELIMITERS) my $t = new Text::Template(TYPE => 'ARRAY', SOURCE => [ @story ], DELIMITERS => ['[', ']']); # fill in the template with the values you read into $hash; # so in the template, [$noun1] => $hash->{'noun1'} my $story = $t->fill_in(HASH => $hash); # then just print it out print $story;

In reply to Re: An Elegance Question by btrott
in thread An Elegance Question by Simplicus

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-24 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found