Created
July 22, 2018 13:01
-
-
Save xtetsuji/5c4fe0e4b0a8cf2a7cefff31d26c636d to your computer and use it in GitHub Desktop.
Rotate 1 character "stick" by carriage return (\r).
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/perl | |
# \r を使って文字のパラパラまんが的なもの | |
use strict; | |
use warnings; | |
use Time::HiRes qw(sleep); | |
# 標準出力は \n を送らないとバッファリングして画面に表示してくれないことがあるので、バッファリングしないでねという指示 | |
$| = 1; # STDOUT のバッファリングをオフにしてほしい | |
#my @chars = qw(\ | / - \ |); # qw 使わず書くと ("\\", "|", "/", "-", "\\", "|") だけど、バッククォートのエスケープが面倒 | |
my @chars = qw(\ | / -); | |
my $i = 0; | |
while (1) { | |
if ( $i >= scalar @chars) { | |
$i = 0; | |
} | |
print "$chars[$i++]"; | |
sleep 0.1; | |
print "\r"; | |
} | |
__END__ | |
for my $char (@chars) { | |
print "$char"; | |
sleep 0.1; | |
print "\r"; | |
} | |
__END__ | |
while ( 1 ) { | |
my $current = localtime(); | |
print "[$current]"; | |
sleep 1; | |
print "\r"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment