Pacific-Design.com

    
Home Index

1. Perl5

2. Hoppity

Perl5 / Hoppity /

perl hoppity.pl file.txt

#!/usr/bin/perl
use strict;
use warnings;

my $inputfile = $ARGV[0];
my $param;

open(FILE, $inputfile);
while (<FILE>)
{
    if ($_ =~ m/(\d+)/)
    {
        $param = $_;
        $param =~ s/\s+//g;
    }
}
close(FILE);

my $num = int($param);

foreach my $num (1 .. $num)
{
    if ((($num % 3) == 0) && (($num % 5) == 0)) { print "Hop\n"; }
    else
    {
        if (($num % 3) == 0) { print "Hoppity\n"; }
        if (($num % 5) == 0) { print "Hophop\n"; }
    }
}