LoginSignup
0
1

More than 1 year has passed since last update.

Perlの備忘録

Last updated at Posted at 2017-10-07

配列をシャッフルする。結果は毎回異なる。

Perl
use List::Util;
@shuffled = List::Util::shuffle @data;

コマンド引数の数を $#ARGV で取得する。実際のコマンド引数よりも1だけ小さい値が格納されている。

Bash
$ cat number_of_command_arguments.pl 
#!/usr/bin/env perl
print "$#ARGV\n"
$ ./number_of_command_arguments.pl first second third fourth fifth
4

dbmファイルを作成、およびそれを読み込む。

Perl
#!/usr/bin/env perl
use English;
use DB_File;
use Fcntl;
my $file_name = 'data.dbm';
my %data;
tie %data, 'DB_File', $file_name, O_CREAT|O_RDWR, 0644, $DB_HASH or die "$OS_ERROR (creating): $file_name";
$data{'key1'} = 'value1';
untie %data;
my %retrieval;
tie %retrieval, 'DB_File', $file_name, O_RDONLY, 0644, $DB_HASH or die "$OS_ERROR (opening): $file_name";
print "$retrieval{'key1'}\n";
untie %retrieval;
exit
0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1