Snippets

sironekotoro Perl入学式 2018 第2回 練習問題 split.pl

Created by sironekotoro

File split.pl Added

  • Ignore whitespace
  • Hide word diff
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+# Perl入学式 2018 第2回 練習問題
+# https://github.com/perl-entrance-org/workshop-2018/blob/master/2nd/slide.md
+# 練習問題(split.pl)
+
+# "There's more than one way to do it." という文字列を作り、split関数で" "(半角スペース)ごとに分割して配列 @array に格納し、出力してください。
+# 好きな文字列を作り、好きな要素で区切って配列 @array2 に格納し、出力してください。
+#     日本語や数字を混ぜてもよいでしょう。
+#     わからないところがあれば、サポーターに聞いてみましょう!
+
+print "Question1\n";
+my $str = "There's more than one way to do it.";
+my @array = split / / , $str;
+for my $element(@array){
+    print "$element\n"
+}
+print "----------\n";
+print "Question2\n";
+use utf8; # スクリプト中に日本語を書く場合は宣言する
+my $pangram = "The-quick-brown-fox-jumps-over-the-lazy-dog";
+my @array2 = split /-/ ,$pangram;
+for my $element(@array2){
+    print $element , "\n"
+}
HTTPS SSH

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