App-Cheats

 view release on metacpan or  search on metacpan

cheats.txt  view on Meta::CPAN

sudo usermod -a -G docker $USER
sudo su $USER # To avoid restarting for groups to take effect
docker pull mailserver/docker-mailserver:latest

# Check docker processes
docker ps
ctop


#############################################################
## Docker Setup
#############################################################

# Enable cgroups in ubuntu (for docker)
sudo vi /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash systemd.unified_cgroup_hierarchy=1 cgroup_enable=memory cgroup_memory=1"
sudo update-grub
reboot

# Check if cgroups is enabled (ubuntu)
cat /proc/cmdline

# Check if using cgroups v1:
ls /sys/fs/cgroup
blkio  cpuacct      cpuset   freezer  memory   net_cls,net_prio  perf_event  rdma     unified
cpu    cpu,cpuacct  devices  hugetlb  net_cls  net_prio          pids        systemd

# Check if using cgroups v2:
ls /sys/fs/cgroup
cgroup.controllers  cgroup.max.descendants  cgroup.stat             cgroup.threads  system.slice
cgroup.max.depth    cgroup.procs            cgroup.subtree_control  init.scope      user.slice


#############################################################
## Docker Build
#############################################################

# Build a docker image based on the Dockerfile
cd ~/tmp/learning_docker/02-*
docker build .
docker images
# EXPOSE 80 in Dockerfile does nothing
docker run -p 3000:80 <IMAGE_ID>
http://localhost:3000/
docker ps
docker stop <CONTAINER_ID>

# Run interactive container (perl shell)
docker run -it perl
docker run -it py-max

# Restart container for CLI
docker start -a -i 99150a04a616

# Run interactive container (bash shell)
docker run -it perl bash

# Go inside a running container.
docker container exec -it feedback-app bash

# Build updated perl image.
docker build -t my-perl .
docker run my-perl -E 'say $^V'

# Rename a docker container
docker container rename <CONTAINER_ID> my-perl-container

# Restart a container
docker container start -a my-perl-container


#############################################################
## Docker Dockerfile Commands
#############################################################
# Dockerfile commands:
# These are executed only during a BUILD.
FROM perl
WORKDIR /app
COPY . /app
RUN echo "Building the image now"
RUN perl -E 'say "Image uses perl version: $^V"'

# Dockerfile commands:
# These are executed only during a RUN.
CMD [ "ls" ]
CMD [ "echo", "Run the container now" ]
CMD [ "perl", "my.pl" ]
#
ENTRYPOINT [ "perl" ]
docker run <IMAGE_ID> -E 'say $^V'

# Dockerfile commands:
# COPY can be controlled by
cat .dockerignore
.git*
node_modules


#############################################################
## Docker Images/Containers
#############################################################

# Images and containers.
# Image     - blueprint.
# Container - instance of image.

# Get an image with perl inside.
docker run perl perl -E 'say $^V'
#
# Or in 2 steps.
docker pull perl
docker images
docker run <IMAGE_ID> perl -E 'say $^V'
docker run -it perl:5.38-slim perl -E 'say 123'

# Dump the contents of an image.
docker image inspect my-perl

# Copy file to/from a container.
# For config files.
docker cp youthful_brown:/app/.bashrc .

cheats.txt  view on Meta::CPAN



#############################################################
## Linux Commands - last, lastlog
#############################################################

# Display all users that are logged in
last
last -i # IP address

# View all last login times for all users
lastlog
lastlog | NOT "Never logged" | AND "Jan\s+(9|10)"

# View last login for a user
last xbe4092


#############################################################
## Linux Commands - ld
#############################################################

# Check if library can be found (gnu make)
ld -libmy.a


#############################################################
## Linux Commands - ldd, ldconfig
#############################################################

# Print shared library dependancies (Added: 2017-10-04 02:02:51 PM)
ldd `which svn`

# configure dynamic library linker run-time bindings (Added: 2017-10-04 02:11:12 PM)
ldconfig -v

# Search locations of system libraries (DES, Setup new machine)
ldconfig -p | grep my_lib


#############################################################
## Linux Commands - libreoffice
#############################################################

# Convert excel to csv on the command line.
# https://help.libreoffice.org/latest/en-GB/text/shared/guide/csv_params.html
#   76 - UTF-8 encoding.
#   44 - Comma.
#   34 - Double quote.
my $csv_format = qq(csv:"Text - txt - csv (StarCalc)":44,34,76);
my $command    = qq(libreoffice --headless --convert-to $csv_format $excel_file);
system $command;
die if $?;


#############################################################
## Linux Commands - locate
#############################################################

# Search for a c header file (DES)
sudo updatedb        # If added from apt-get
locate my_header


#############################################################
## Linux Commands - ls, ll
#############################################################

# Apply a character class to list (ls files)
ll *2[1-3]


#############################################################
## Linux Commands - mail
#############################################################

# Email the contents of a file to someone
echo $(cat mail.dat) | mail -s "File Name" timofey.potapov@pw.utc.com

# Print fixed width (monospace) emails
cat batch_report.formatted | perl -le 'print "<html><body><pre>\n", <>, "\n</pre></body></html>"' | mail -s "html report -a " -a "Content-Type: text/html" timofey.potapov@pw.utc.com

# Send email with a file as an attachment
cat ENV_linux.txt | mail -s "attachement" -a "Content-Type: html" timofey.potapov@pw.utc.com

# Send mail from another bench
ssh potapov@lnxbr25 'cat ~/bin/date.dat | mail -s "subject" timofey.potapov@pw.utc.com'

# Find out which benches can send emails
run_on_all_benches.p 'echo "on bench `uname -n`" | mail -s "`uname -n`" melvin.williams@pw.utc.com'

# View emails on bench
mail

# Delete single email of yours on bench
mail
>> d

# Delete all your emails on bench
mail
>> d*


#############################################################
## Linux Commands - man
#############################################################

# Show the location of all man page (manual/pod)
man --where --all date

# read a specific man page when there are many with the same name (Added: 2017-11-02 09:04:16 AM)
man -k readlink
man 2 readlink


#############################################################
## Linux Commands - mktemp
#############################################################

# Create a randomly named temp file.
mktemp

cheats.txt  view on Meta::CPAN

    PS1+=" "
}


#############################################################
## Linux Commands - xxd
#############################################################

# Convert a binary file to hex
xxd NVM_EDF_CHA.dat > tmp_file

# Convert a hex file to binary
xxd -r tmp_file > tmp.bin

# Open a binary file in hex with vim
vi <(xxd tmp.bin)


#############################################################
## Linux Commands - ypcat
#############################################################

# View password file on main server (yellow page cat)
ypcat passwd

# Add ypcat passwd command if missing
vi /var/yp/nicknames
# add entry: passwd      passwd.byname

# Return users which are found in the yellow pages password file
cat user_deletion_list | perl -ne 'print `ypcat passwd | grep $_` ' > found_in_yp

# Remove/Delete a user account
 1. Check username in Outlook (CTRL-K)
 2. Check username in Yellow Pages (ypcat passwd | grep username)
 3. Go to file server
sudo userdel -r username	# -r does this: sudo rm -rf username
sudo make -C /var/yp


#############################################################
## Linux Commands - yppasswd
#############################################################

# Change your password
yppasswd


#############################################################
## Linux Commands - zero
#############################################################

# Clear NVM/flash memory (from start to and including the end address)
zero -p ppa -s 0xSTART_ADDRESS -e 0xEND_ADDRESS


#############################################################
## Linux Accounts
#############################################################

# Check when a users account was created (good unless file was updated or touched)
ll ~SOME_USER/.bash_logout

# Check when a users account was created (good unless home account changed)
ll -d ~SOME_USER
echo ~SOME_USER | perl -lne 'print for -M,-C,-A'


#############################################################
## Linux Hardware
#############################################################

# View how many processors are on a machine/bench
cat proc/cpuinfo
cat /proc/cpuinfo | perl -ln0777e "print ~~split qq(\n\n)"
nproc

# Find out the service tag code of a machine (Bob)
# That is the same as the serial number
# Used for compability purposes (such as when getting new drives)
/usr/sbin/dmidecode | perl -ln00e 'print if /System Information/'

# Find out easily how many cpu there are (a command)
lscpu

# Check if using intel or AMD. (linux)
lscpu | grep 'Vendor ID'

# Add module to kernel (DES,UI,insert,library)
insmod /lib/modules/2.6.11/kernel/fs/fat/fat.ko
modprobe msdos

# Find out version of debian you are running (DES)
cat /etc/debian_version

# Check processor family (DES,UI)
grep "cpu family" /proc/cpuinfo
# Cpu family of "6" means use "Pentium-Pro"

# Change boot loader to use certain cpu's (DES,UI,Mark,shielding)
cd /boot/grub
sudo vi grub.cfg
/\Vlinux /boot/vmlinuz-3.16.51+20180205+1524
/\Vlinux /boot/vmlinuz-3.16.51+20180205+1524
# Add this to
isolcpus=0,1,2,3,4,5,6,7,8,9
cat /proc/cmdline

# Check timer frequency (DES,UI,CONFIG_HZ_1000)
cat /usr/src/linux.config | OR CONFIG_COMPAT_BRK CONFIG_HZ_PERIODIC CONFIG_X86_GENERIC CONFIG_SCHED_SMT CONFIG_HZ_1000

# find biggest binary number on the machine
perl -lE '@a=split //, sprintf "%b",  ~~-1; print @a'
perl -lE '@a=split //, sprintf "%b",  ~~-1; print scalar @a'

# Size of an integer on this system
perl -le 'print length pack "i"'


#############################################################
## Linux File Properties - General

cheats.txt  view on Meta::CPAN

perl -MCwd -le 'print getcwd'

# Get absolute path to a file (works same for link and regular files,DES)
perl -MCwd=realpath  -le '$_="file"; print realpath($_)'


#############################################################
## Perl Modules - DateTime
#############################################################

# Create expiration dates (Start of tomorrow,start of next week)
perl -MDateTime -E '$dt = DateTime->now; say $dt->add(days => 1)->truncate(to => "day" )'
# 2021-08-06T00:00:00
perl -MDateTime -E '$dt = DateTime->now; say $dt->add(weeks => 1)->truncate(to => "local_week" )'
# 2021-08-08T00:00:00

# Truncate date to start of this week (Monday).
perl -MDateTime -E '$dt = DateTime->now; say $dt->truncate(to => "week" )->strftime("%e %b %Y")'

# Truncate date to end of 3 weeks from now on a Friday.
perl -MDateTime -E '$dt = DateTime->now; say $dt->truncate(to => "week" )->add(weeks => 3, days => 4)->strftime("%e %b %Y")'


#############################################################
## Perl Modules - Data::DPath
#############################################################

# Recurse through a data structure and print matches.
perl -MData::DPath -Mojo -E 'my $data = {a => [0, {complex => 1}]}; say "\nBefore:"; say r $data; for my $node ( grep {ref} Data::DPath->match($data, "//") ){ say "Tying: $node: " . r $node}'
#
# Before:
# {
#   "a" => [
#     0,
#     {
#       "complex" => 1
#     }
#   ]
# }
#
# Tying: ARRAY(0xb400007e98818a28): [
#   0,
#   {
#     "complex" => 1
#   }
# ]
#
# Tying: HASH(0xb400007e98818698): {
#   "complex" => 1
# }
#
# Tying: HASH(0xb400007e988291f0): {
#   "a" => [
#     0,
#     {
#       "complex" => 1
#     }
#   ]
# }

# Show where a complex data structure is being updated.
perl -MData::DPath -MCarp=longmess -MTie::Watch -Mojo -E 'my $data = {a => [0, {complex => 1}]}; say "\nBefore:"; say r $data; for my $node ( grep {ref} Data::DPath->match($data, "//") ){ say "Tying: $node"; Tie::Watch->new( -variable => $node, -stor...


#############################################################
## Perl Modules - Data::Dumper
#############################################################

# Deparse a subroutine in a data structure
perl -MData::Dumper -le '$ref=sub{print "in sub"}; &$ref; my $d=Data::Dumper->new([$ref])->Deparse(1); print $d->Dump'

# Deparse/show the code of a subroutine
perl -MData::Dumper -le '$Data::Dumper::Deparse=1; sub add{my($a,$b)=@_; $a+$b}; print Dumper \&add'
perl -MData::Dumper -le '$Data::Dumper::Deparse=1; $add=sub{my($a,$b)=@_; $a+$b}; print Dumper $add'

# Data Dumper subroutine template
sub _dumper {
    require Data::Dumper;
    my $data = Data::Dumper
      ->new( [@_] )
      ->Indent( 1 )
      ->Sortkeys( 1 )
      ->Terse( 1 )
      ->Useqq( 1 )
      ->Dump;
    return $data if defined wantarray;
    say $data;
}


#############################################################
## Perl Modules - Data::Printer
#############################################################

# Colorful data dumper.
# p  - print.
# np - capture dump output.
perl -MData::Printer -E 'my $var = [1..3, {a => 1, b => 2}, 123]; p $var'
[
    [0] 1,
    [1] 2,
    [2] 3,
    [3] {
            a   1,
            b   2
        },
    [4] 123
]


#############################################################
## Perl Modules - Data::Trace
#############################################################

# Show where a complex data structure is being updated.
cpanm Data::Trace
perl -MData::Trace -Mojo -E 'my $data = {a => [0, {complex => 1}]}; say "\nBefore:"; say r $data; Data::Trace->Trace($data); sub BadCall{ $data->{a}[0] = 1 } say ""; BadCall(); say "After:"; say r $data'

# Data::Trace (WIP).
perl -Me -MData::Trace -E 'get("Kernel::System::Cache")->Set( Type => "Ticket", Key => "ABC", Value => [1..3] ); Data::Trace->Trace( get("Kernel::System::Cache") ); get("Kernel::System::Cache")->Delete( Type => "Ticket", Key => "ABC" )'


#############################################################
## Perl Modules - DBD::mysql
#############################################################

# Bug in DBD::mysql before version 5.007:
#
cpanm DBD::mysql@5.006
perl -Me2 -e '$d = get("Kernel::System::DB"); $d->Connect; $d->Disconnect; $d->Connect; say "END"'
ConnectCached
Disconnect
ConnectCached
Segmentation fault (core dumped)
#
cpanm DBD::mysql@5.007
perl -Me2 -e '$d = get("Kernel::System::DB"); $d->Connect; $d->Disconnect; $d->Connect; say "END"'
ConnectCached
Disconnect
ConnectCached
END


#############################################################
## Perl Modules - DBI
#############################################################

# How to connect to database using perl DBI (postgres,sample,sql)
perl -MDBI -E '$dbh = DBI->connect("DBI:Pg:dbname=$db; host=127.0.0.1", "$user", "$pass", {RaiseError => 1}) or die $DBI::errstr; say "\nOpened db successfully!\n"'

# How to query information from a database using perl (postgres,sample,sql)
perl -MDBI -E 'sub Die { die $DBI::errstr } $dbh = DBI->connect("DBI:Pg:$db=srto_8_0; host=127.0.0.1", "$user", "$pass", {RaiseError => 1}) or Die; $sth = $dbh->prepare(q(SELECT * from MyTable;)) or Die; $sth->execute() or Die; while(@row = $sth->fet...

# Fetchbdata from SQLite database.
perl -MDBI -E 'my $dbh = DBI->connect("DBI:SQLite:kjv.bbl.mybible", '', '', {RaiseError => 1}); my $sth = $dbh->prepare("select * from Bible limit 3"); $sth->execute; while(my @row = $sth->fetchrow_array ){ say "@row" } $dbh->disconnect'
perl -MDBI -E 'my $dbh = DBI->connect("DBI:SQLite:kjv.bbl.mybible", '', '', {RaiseError => 1}); my $all = $dbh->selectall_arrayref("select * from Bible limit 3"); for my $row ( @$all ){ say "@$row" } $dbh->disconnect'
perl -MDBI -E 'my $dbh = DBI->connect("DBI:SQLite:kjv.bbl.mybible", '', '', {RaiseError => 1}); for my $row ( $dbh->selectall_array("select * from Bible limit 3") ){ say "@$row" } $dbh->disconnect'

# View install drivers for DBI.
perl -MDBI -E 'say for DBI::available_drivers'

# Example using selectrow_hashref.
perl -MData::Printer -MDBI -E 'my $t=shift; my $d = DBI->connect("DBI:SQLite:$t"); my $r = $d->selectrow_hashref("select * from details"); p $r' $t


#############################################################
## Perl Modules - DBI::Profile
#############################################################

# Profile SQL statements in perl DBI.
# Install and export.
cpanm DBI::Profile
export DBI_PROFILE='!Statement'
#
# Report explicitly (instead of on DESTROY)

cheats.txt  view on Meta::CPAN

## Perl Modules - Devel::REPL
#############################################################

# Using a read,evaluate,print,loop in perl.
perl -MDevel::REPL -E '
    my  $my_var  = 111;
    our $our_var = 222;
    my $repl = Devel::REPL->new;
    $repl->load_plugin($_) for qw(
        History
        LexEnv
        DDS
        Colors
        Completion
        CompletionDriver::INC
        CompletionDriver::LexEnv
        CompletionDriver::Keywords
        CompletionDriver::Methods
    );
    $repl->run;
'

#############################################################
## Perl Modules - Devel::Size
#############################################################

# Find out the size of variables.
use Devel::Size qw( total_size );
say "size: " . total_size($bytes);


#############################################################
## Perl Modules - Email::Address::XS
#############################################################

# Example of using Email::Address::XS
perl -Mojo -MEmail::Address::XS -E 'say r $_ for Email::Address::XS->parse("First Last email\@localhost")'
bless( {
  "comment" => undef,
  "host" => undef,
  "invalid" => 1,
  "original" => "First ",
  "phrase" => undef,
  "user" => "First"
}, 'Email::Address::XS' )


#############################################################
## Perl Modules - Email::Outlook::Message
#############################################################

# Parse an outlook message .msg file
perl -MEmail::Outlook::Message -le 'print Email::Outlook::Message->new(shift)->to_email_mime->as_string' "$m"


#############################################################
## Perl Modules - Enbugger
#############################################################

# Using a read,evaluate,print,loop in perl.
# Not updated since 2014 and failing to build.


#############################################################
## Perl Modules - Encode
#############################################################

# Example of using Encode to show string in different supported encodings (broken).
perl -C -MEncode -E '$s1="Ue: Ü"; $s2="Euro: \N{EURO SIGN}"; for ( encodings ) { printf "%-15s: [%-7s] [%s]\n", $_, encode($_,$s1), encode($_,$s2) }'

# Why use Encode?
perl -E 'say "\xe1"'    # �
perl -C -E 'say "\xe1"' # á
perl -MEncode -E 'say encode "UTF-8", "\xe1"' # á
perl -MEncode -E 'use open ":std", ":encoding(UTF-8)"; say "\xe1"' # á
perl -MEncode -E 'use open qw(:std :utf8); say "\xe1"' # á

# Mixed up encoding.
perl -MEncode -E '$s = encode("UTF-8","é", Encode::FB_CROAK|Encode::LEAVE_SRC); say length($s) . " $s"'
4 é
perl -C -MEncode -E '$s = encode("UTF-8","é", Encode::FB_CROAK|Encode::LEAVE_SRC); say length($s) . " $s"'
4 é
perl -Mutf8  -MEncode -E '$s = encode("UTF-8","é", Encode::FB_CROAK|Encode::LEAVE_SRC); say length($s) . " $s"'
2 é
perl -C -Mutf8  -MEncode -E '$s = encode("UTF-8","é", Encode::FB_CROAK|Encode::LEAVE_SRC); say length($s) . " $s"'
2 é

# Decoding example.
perl -C -MEncode -E 'say decode("UTF-8", chr(0xc3).chr(0xa9), Encode::FB_CROAK)'
é


#############################################################
## Perl Modules - Excel::Writer::XLSX
#############################################################

# Excel - Simple: Generate a blank xlsx file
perl -MExcel::Writer::XLSX -E "$wb = Excel::Writer::XLSX->new('my.xlsx'); $wb->close"

# Excel - Simple: Check for errors openning an excel file and write to a cell
# Also rename the worksheet
perl -MExcel::Writer::XLSX -E "$wb = Excel::Writer::XLSX->new('my.xlsx') or die qq($!\n); $ws = $wb->add_worksheet('my'); $ws->write('A1', 'Hello Excel'); $wb->close"

# Excel - Simple: Add a format to make a cell bold
perl -MExcel::Writer::XLSX -E "$wb = Excel::Writer::XLSX->new('my.xlsx') or die qq($!\n); $ws = $wb->add_worksheet('my'); $format = $wb->add_format; $format->set_bold; $ws->write(0, 0, 'Hello Excel', $format); $wb->close"

# Create a spreadsheet/excel with formulas using perl (only on lnxbr42)
perl -MExcel::Writer::XLSX -le '
   $wb=Excel::Writer::XLSX->new("new.xlsx");
   $ws=$wb->add_worksheet;
   $ws->write("A1","In Excel");
   $ws->write("B2",3);
   $ws->write("B3",4);
   $ws->write("B4","=B2+B3");
   $ws->write("B5","=SUM(B2:B4)");
   $wb->close
'

# Create a spreadsheet/excel with color formats using perl (only on lnxbr42)
perl -MExcel::Writer::XLSX -le '
   $wb=Excel::Writer::XLSX->new("new2.xlsx");

cheats.txt  view on Meta::CPAN


# Perl Modules - Text::ParseWords example.
sub get_file_data{
	use Text::ParseWords;
	map{chomp; [quotewords('\s+', 1, $_)]} <DATA>;
}


#############################################################
## Perl Modules - Tie::Array
#############################################################

# Tie a simple array variable
perl -MData::Dumper -MTie::Array -le 'tie @a, "Tie::StdArray"; @a=(1,3,4); print Dumper tied @a'


#############################################################
## Perl Modules - Tie::File
#############################################################

# Tie an array to a file
perl -MTie::File -le 'tie @file,"Tie::File","array.pl"; print $file[4]'


#############################################################
## Perl Modules - Tie::Hash
#############################################################

# Tie a simple hash variable
perl -MData::Dumper -MTie::Hash -le 'tie %h, "Tie::StdHash"; $h{age}=123; print Dumper tied %h'

# Tie append hash example.
package Tie::AppendHash;   
use Tie::Hash;   
our @ISA = qw(Tie::StdHash);   
sub STORE {       
    my ($self, $key, $value) = @_;       
    push @{$self->{$key}}, $value;   
}  


#############################################################
## Perl Modules - Tie::Scalar
#############################################################

# Tie a simple scalar variable
perl -MData::Dumper -MTie::Scalar -le 'tie $n, "Tie::StdScalar"; $n=5; print Dumper tied $n'
perl -Me -MTie::Scalar -e 'my $obj = tie $var, "Tie::StdScalar"; $var=5; p $var; p $obj'

# Tie to scalar (without template)
perl -le '{package P; sub TIESCALAR{my($c,$o)=@_; bless \$o,$c} sub FETCH{my($s)=@_; $$s} sub STORE{my($s,$v)=@_; $$s = $v} } tie $var, "P", 123; print $var; $var=42; print $var'


#############################################################
## Perl Modules - Tie::Watch
#############################################################

# Tie Watch. OOP interface that hides making packages for tied variables
perl -MTie::Watch -le 'my $v=1; Tie::Watch->new(-variable => \$v, -fetch => sub{my $s=shift; $v=$s->Fetch; $s->Store($v+1); $v}); print $v; print $v; print $v'

# Check when a variable is updated. (watcher)
perl -MTie::Watch -Mojo -le 'my $h={a => [1..2]}; say r $h; Tie::Watch->new( -variable => \$h->{a}, -store => sub{my ($s,$v) = @_; $s->Store($v); my $Scope = 0; while( my ($Pkg,$Line) = caller(++$Scope) ){ say "$Pkg:$Line" } }); sub func{$h->{a}=456}...

# Check when a variable is updated. (watcher)
use Tie::Watch;
Tie::Watch->new(
   -variable => \$Self->{Cache}->{ $Param{Type} }->{ $Param{Key} },
   -store    => sub{
       my ($S,$Value) = @_;
       $S->Store($Value);
       my $Scope = 0;
       my $Limit = 5;
       while( my ($Package,$Line) = (caller(++$Scope))[0,2] ){
          next if $Package =~ /\ATie::/;
          say "* Store: $Package line $Line";
          last if $Scope >= $Limit;
       }
   },
);

# Problem using Tie::Watch with Storable::dclone.
perl -MData::Tie::Watch -MStorable -e '$data = {}; $obj = Data::Tie::Watch->new( -variable => $data ); Storable::dclone($data)'
perl -MData::Tie::Watch -MStorable -e '$data = 111; $obj = Data::Tie::Watch->new( -variable => \$data ); Storable::dclone(\$data)'
Can't store CODE items at -e line 1.

# Sample test code.
perl -Me -Ilib -MData::Tie::Watch -e '{ my $data = []; Data::Tie::Watch->new( -variable => $data ); my $d2 = {}; Data::Tie::Watch->new( -variable => $d2 ); } say "DONE"'
perl -Me -Ilib -MData::Trace -e '{ my $d1 = []; my $d2 = {}; Trace($d1); Trace($d2); $d1->[2] = 22; $d2->{cat} = 1 } say "DONE"; use Data::Tie::Watch; p \%Data::Tie::Watch::METHODS'


#############################################################
## Perl Modules - Time::HiRes
#############################################################

# Perl Modules - Time::HiRes
# Higher resolution sleeps.
perl -MTime::HiRes=sleep -E 'sleep 0.25 and say "sleeping" while 1'


#############################################################
## Perl Modules - Time::Moment
#############################################################

# Difference between with_offset_same_instant and with_offset_same_local.
# Instant form will use the time zone from the object (Probably what you want).
perl -MTime::Moment -E '$tm = Time::Moment->now; $tmi = $tm->with_offset_same_instant(0); $tml = $tm->with_offset_same_local(0); say "Normal:   $tm"; say "Instance: $tmi"; say "Local:    $tml"'
# Normal:   2022-03-10T18:44:46.882016+01:00
# Instance: 2022-03-10T17:44:46.882016Z
# Local:    2022-03-10T18:44:46.882016Z

# Timestamp using milliseconds.
perl -MTime::Moment -E 'say Time::Moment->now->strftime("%Y/%m/%d-%T%3f")'


#############################################################
## Perl Modules - Time::Piece
#############################################################

# Prefer using Time::Piece over DateTime if possible
#
# 1. Less dependencies:
cpanm --showdeps Time::Piece -q | wc -l   # 4
cpanm --showdeps DateTime -q | wc -l      # 35
#



( run in 2.179 seconds using v1.01-cache-2.11-cpan-8f98c5d2c55 )