Created
July 13, 2019 05:07
-
-
Save sironekotoro/e25d9d2e3c3c79880a5b14ce0fe29050 to your computer and use it in GitHub Desktop.
Perl入学式 2019第3回 即席の正規表現練習問題
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my $date = '07-13-2019'; | |
# 「2019-07-13」の形式に直す。 | |
# 正規表現でキャプチャしたものを並べ替える | |
$date =~ /(\d+)-(\d+)-(\d+)/; | |
print $3 . '-' . $1 . '-' . $2 . "\n"; | |
# 正規表現でキャプチャしたもので置換する | |
$date =~ s/(\d+)-(\d+)-(\d+)/$3-$1-$2/; | |
print $date . "\n"; | |
# おまけ・正規表現を使わない方法 | |
$date = '07-13-2019'; | |
my @array = split /-/, $date; | |
my $ymd = join '-', ( $array[2], $array[0], $array[1] ); | |
print $ymd . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment