Sha256: 64dbc5ac730bdbf21eb9f025b3d807201c49355abf6813f062ee6aa860822134

Contents?: true

Size: 1.17 KB

Versions: 323

Compression:

Stored size: 1.17 KB

Contents

package Example;

use strict;
use warnings;

sub new {
    my $class = shift;
    return bless {}, $class;
}

sub recite {
    my $self = shift;
    my @rhyme;
    my @lines = (
        ['the house that Jack built.'],
        ['the malt', 'that lay in'],
        ['the rat', 'that ate'],
        ['the cat', 'that killed'],
        ['the dog', 'that worried'],
        ['the cow with the crumpled horn', 'that tossed'],
        ['the maiden all forlorn', 'that milked'],
        ['the man all tattered and torn', 'that kissed'],
        ['the priest all shaven and shorn', 'that married'],
        ['the rooster that crowed in the morn', 'that woke'],
        ['the farmer sowing his corn', 'that kept'],
        ['the horse and the hound and the horn', 'that belonged to'],
    );

    my @repeat;

    foreach my $i (0..$#lines) {
        my $block = "This is $lines[$i]->[0]\n";
        my $j     = $i - 1;
        my $that  = $lines[$i]->[1];

        while ($j >= 0) {
            $block .= "$that $repeat[$j]->[0]\n";
            $that   = $repeat[$j]->[1];
            $j--;
        }

        push @repeat, $lines[$i];
        push @rhyme,  $block;
    }

    return join "\n", @rhyme;
}

1;

Version data entries

323 entries across 323 versions & 1 rubygems

Version Path
trackler-2.2.1.105 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.104 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.103 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.102 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.101 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.100 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.99 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.98 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.97 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.96 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.95 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.94 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.93 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.92 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.91 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.90 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.89 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.88 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.87 tracks/perl5/exercises/house/Example.pm
trackler-2.2.1.86 tracks/perl5/exercises/house/Example.pm