CSV
read CSV
write CSV
use Text::CSV_XS qw[];
Text::CSV_XS::csv(
in => Array[HashRef],
out => 'filename.csv',
headers => [qw[field1 field2 ...]],
binary => 1,
encoding => 'UTF-8',
decode_utf8 => 0,
eol => $LF,
);
PostgreSQL
uuid
https://www.postgresql.org/docs/current/static/uuid-ossp.html
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
# use UUID v1 - based on MAC addr.
"id" UUID PRIMARY KEY NOT NULL DEFAULT uuid_generate_v1()
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
# use UUID v5 - random
"id" UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid()
MySQL
connect
my $dbh = DBI->connect(
qq[DBI:mysql:database=$self->{cfg}->{MYSQL}->{db};host=$self->{cfg}->{MYSQL}->{host};port=$self->{cfg}->{MYSQL}->{port}],
$self->{cfg}->{MYSQL}->{username},
$self->{cfg}->{MYSQL}->{password},
{ RaiseError => 1,
PrintWarn => 0,
ShowErrorStatement => 1,
mysql_auto_reconnect => 1,
mysql_enable_utf8mb4 => 1,
mysql_multi_statements => 1,
}
);
create table
CREATE TABLE IF NOT EXISTS `table` (
`id` VARCHAR(20) NOT NULL,
PRIMARY KEY (`player_id`)
) DEFAULT CHARSET=utf8mb4;
SQLite
field with the current unix timestamp by default
"unix_timestamp" INTEGER NOT NULL DEFAULT(CAST(STRFTIME('%s', 'now') AS INT))
Other
perl tail recursion
@_ = ($arg1, $arg2, ...);
goto &method;