This does all twelve stanzas of London Bridge. Also, it passes the defaults for

perlcritic -harsh
. Enjoy. (Update: removed a line that toolic noticed was never used.)

#!/usr/bin/perl use strict; use warnings; my @armed_guard = ("watch all night", "fall asleep", +"smoke all night"); my @royal_decree = ("Set a man to", "Suppose the man should", "Gi +ve him a pipe to"); my @building_outcome = ("falling down", "wash away", "will not stay" +, "bend and bow", "stolen away"); my @building_material = ("London Bridge", "wood and clay","bricks and +mortar", "iron and steel","silver and gold"); my @phrase_glue = ("is", "will", "", + "will", "will be"); my $fair_lady = "My fair Lady.\n\n"; # First stanza print join(" ",$building_material[0],$phrase_glue[0],$building_outcome +[0]). ",\n"; print $building_outcome[0] . ", " . $building_outcome[0] . ",\n"; print join(" ",$building_material[0],$phrase_glue[0],$building_outcome +[0]). ",\n"; print $fair_lady; # middle 8 stanzas for my $i (1..$#building_outcome) { print "Build it up with ".$building_material[$i].",\n"; print $building_material[$i] . ", " . $building_material[$i] . + ",\n"; print "Build it up with ".$building_material[$i].",\n"; print $fair_lady; print join(" ",ucfirst($building_material[$i]),$phrase_glue[$i +],$building_outcome[$i]).",\n"; print $building_outcome[$i] . ", " . $building_outcome[$i] . " +,\n"; print join(" ",ucfirst($building_material[$i]),$phrase_glue[$i +],$building_outcome[$i]).",\n"; print $fair_lady; } # final 3 stanzas for my $i (0..2) { print join(" ", $royal_decree[$i], $armed_guard[$i]).",\n"; print $armed_guard[$i].", ".$armed_guard[$i].",\n"; print join(" ", $royal_decree[$i], $armed_guard[$i]).",\n"; print $fair_lady; } exit 0;
--
I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.

Replies are listed 'Best First'.
Re: London Bridge (build it up with lots of arrays, lots of array, lots of arrays)
by toolic (Bishop) on Dec 10, 2007 at 21:07 UTC
    funny++

    Couple of comments. You're not using $directive, and you don't really need join.

      Thanks. I only needed join to get a space between the phrases. Otherwise I was getting "London Bridgeisfalling down". Not sure how I missed 'directive'. I might update that.

      --
      I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.
        The following produces the same output without the join. It just seems simpler to me, but it's all a matter of personal preference:
        print "$building_material[0] $phrase_glue[0] $building_outcome[0],\n";