Jesse Smith has asked for the wisdom of the Perl Monks concerning the following question:

The closest I can get is...
#!/usr/bin/perl -w use strict; my @array = ('words', 'will', 'go', 'here'); my @array2 = ('words2', 'will2', 'go2', 'here2'); print "Content-Type: text/html\n\n"; print "$array[rand @array] - $array2[rand @array2]\n";
But I can only post one line of content. How can I post it like this...
#!/usr/bin/perl -w use strict; my @array = ('words', 'will', 'go', 'here'); $array[rand @array] my @array2 = ('words2', 'will2', 'go2', 'here2'); $array2[rand @array2] print "Content-Type: text/html\n\n"; print <<EOM; <title>Title goes here</title> <H1>HTML can now go here</H1> <P> Then the random words go anywhere as $array and $array2... <P> $array <P> $array2 <P> Footer text can go here!!! EOM exit; }
so I can include a page of HTML with the random words?

Replies are listed 'Best First'.
Re: Print out random words with HTML
by AnomalousMonk (Archbishop) on Oct 12, 2016 at 04:07 UTC

    Here-docs use "standard" double-quotish interpolation, so I don't see why

    print <<EOM; <P> The random words can go anywhere... <br> random $array[ rand @array ] words $array2[ rand @array2 ] here <br> Footer text can go here!!! </P> EOM
    wouldn't work. Have you tried it?


    Give a man a fish:  <%-{-{-{-<

      Turns out you need more than just
      '$array[rand @array]'
      Having
      $array = $array[ rand @array ]; $array2 = $array2[ rand @array2 ];
      does it.
      #!/usr/bin/perl #use strict; my @array = ('words', 'will', 'go', 'here'); my @array2 = ('words2', 'will2', 'go2', 'here2'); $array = "$array[rand@array]"; $array2 = $array2[rand@array2]; { print "Content-Type: text/html\n\n"; print <<EOM; <H1>$array</H1> <HR> <H1>$array2</H1> EOM exit; }

        Hello Jesse Smith,

        Actually AnomalousMonk’s approach works fine:

        use strict; use warnings; my @array1 = qw( QUICK BROWN FOX ); my @array2 = qw( JUMPED UNFORTUNATE DOG ); print <<EOM; <P> The random words can go anywhere... <br> random $array1[ rand @array1 ] words $array2[ rand @array2 ] here <br> Footer text can go here!!! </P> EOM

        Output:

        Why do you think otherwise?

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,