Snippets

sironekotoro Perl入学式 2018 第3回 練習問題 hash_func.pl

Created by sironekotoro
#!/usr/bin/env perl
use strict;
use warnings;

# Perl入学式 2018 第3回 練習問題
# https://github.com/perl-entrance-org/workshop-2018/blob/master/3rd/slide.md
# 練習問題(hash_func.pl)

# 次の処理をする hash_func.pl を作りましょう。
# 1. keys関数を使って、hash_profile.pl で作ったハッシュのkeyをすべて出力してください。
my %my_profile = ( name => 'sironekotoro', age => '200', food => 'ramen' );
my @keys = keys %my_profile;
print "@keys", "\n";

# 2. delete関数を使って、1で使ったハッシュから年齢(age)の要素を削除してください。
delete $my_profile{age};

# 3. exists関数を使って、年齢の要素が存在するか確認してください。存在している場合は "Age is exist." 、存在しない場合は "Age is not exist." と表示するようにしてみましょう。
if ( exists $my_profile{age} ) {
    print "Age is exist.\n";
}
else {
    print "Age is not exist.\n";
}

Comments (0)

HTTPS SSH

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