Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Created July 22, 2018 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtetsuji/5c4fe0e4b0a8cf2a7cefff31d26c636d to your computer and use it in GitHub Desktop.
Save xtetsuji/5c4fe0e4b0a8cf2a7cefff31d26c636d to your computer and use it in GitHub Desktop.
Rotate 1 character "stick" by carriage return (\r).
#!/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