Created
February 9, 2025 08:08
-
-
Save noqisofon/6f9b1639ac5852dfc306139920a00aee to your computer and use it in GitHub Desktop.
( ノ╹◡◡╹)ノ ファイルの内容からランダムに大体 6 行表示するかもしれない
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 | |
# -*- mode: perl; -*- | |
use v5.38.2; | |
use Data::Entropy::Algorithms qw(rand_int choose_r); | |
use Getopt::Long; | |
use Path::Class; | |
use Pod::Usage; | |
my $amount = rand_int(6) + 1; | |
my $help = 0; | |
GetOptions( | |
'count|amount=i' => \$amount, | |
'help|?' => \$help | |
) or pod2usage(2); | |
pod2usage(1) if $help; | |
for my $arg (@ARGV) { | |
my @lines = file($arg)->slurp(chomp => 1); | |
my $choosen = choose_r($amount, \@lines); | |
for my $item (@$choosen) { | |
say $item; | |
} | |
} | |
__END__ | |
=head1 NAME | |
choice - Displays 1d6 random lines from the specified file. | |
=head1 SYNOPSIS | |
choice [options] [file ...] | |
Options: | |
--amount N display N random lines | |
--help brief help message | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment