Snippets

sironekotoro Perl入学式 2018 第5回 練習問題 fizzbuzz

Created by sironekotoro

File fizzbuzz.pl Added

  • Ignore whitespace
  • Hide word diff
+#!/usr/bin/env perl
+use Mojolicious::Lite;
+
+# Perl入学式 2018 第5回 練習問題 fizzbuzz
+# https://github.com/perl-entrance-org/workshop-2018/blob/master/5th/slide.md#%E7%B7%B4%E7%BF%92%E5%95%8F%E9%A1%8C-1
+
+# Documentation browser under "/perldoc"
+plugin 'PODRenderer';
+
+get '/' => sub {
+    my $c = shift;
+    $c->render( template => 'index' );
+};
+
+get '/fizzbuzz' => sub {
+    my $c = shift;
+
+    $c->render( template => 'fizzbuzz' );
+};
+
+app->start;
+__DATA__
+
+@@ index.html.ep
+% layout 'default';
+% title 'Welcome';
+
+<h1>Perl入学式 2018 第5回 練習問題 fizzbuzz</h1>
+<a href="https://github.com/perl-entrance-org/workshop-2018/blob/master/5th/slide.md#%E7%B7%B4%E7%BF%92%E5%95%8F%E9%A1%8C-1">https://github.com/perl-entrance-org/workshop-2018/blob/master/5th/slide.md#%E7%B7%B4%E7%BF%92%E5%95%8F%E9%A1%8C-1</a>
+
+<ul>
+  <li>fizzbuzzテンプレートを用意して, 1から100までのfizzbuzzを表示してみましょう</li>
+  <ul>
+    <li>但し, fizzbuzzの処理は全てfizzbuzzテンプレートの中に書くようにしましょう</li>
+  </ul>
+  <li>fizzbuzz</li>
+  <ul>
+    <li>3で割り切れる場合「Fizz」</li>
+    <li>5で割り切れる場合「Buzz」</li>
+    <li>3でも5でも割り切れる場合「fizzbuzz」</li>
+    <li>いずれも満たさない場合「その数をそのまま」</li>
+  </ul>
+</ul>
+
+<p><%= link_to 練習問題 => 'fizzbuzz'%></p>
+
+@@ fizzbuzz.html.ep
+% layout 'default';
+% title 'fizzbuzz';
+<h1>fizzbuzz</h1>
+
+% for my $i (1 .. 100){
+
+  % if ($i % 15 == 0){
+    <br>fizzbuzz</br>
+  % }elsif($i % 3 == 0){
+    <br>Fizz</br>
+  % }elsif($i % 5 == 0){
+    <br>Buzz</br>
+  % }else{
+    <br><%= $i %></br>
+  % }
+
+% }
+
+@@ layouts/default.html.ep
+<!DOCTYPE html>
+<html>
+  <head><title><%= title %></title></head>
+  <body><%= content %></body>
+</html>
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.