A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Add a password to a MySQL login

Many applications require there to be a password.

SELECT host, user FROM mysql.user;

SET PASSWORD FOR 'bob'@'%.loc.gov' = PASSWORD('newpass');

Perl DBI

This is the one you want:

$ary_ref = $dbh->selectcol_arrayref($statement);

Perl map command

%hash = map { get_a_key_for($_) => $_ } @array;

http://perldoc.perl.org/functions/map.html


How to convert a tab separated file into a Perl hashref


open(LIST,'<',$datafile) || die "Failed to open ".$datafile;
my @header = split("\t", <list>);
chomp(@header);
my @nodes = ();
while (my $line = <LIST>) {
chomp($line);
my $i=0; my %node = map { $header[$i++] => ($_?$_:'[empty field]') } split("\t", $line);
push @nodes, \%node;
}
close(LIST);

print Dumper(\@nodes);

Simple log4perl config

log4perl.rootLogger=DEBUG, STDERR
log4perl.appender.STDERR=Log::Log4perl::Appender::Screen
log4perl.appender.STDERR.layout=PatternLayout
log4perl.appender.STDERR.layout.ConversionPattern=[%d] [%p %c] - %m%n