One of the reasons I like Perl – it’s really fast on solving daily routines. The request was to get a list of shipping flags from one of the websites to Excel and paste it to the site’s database. Quick and dirty solution:
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Spreadsheet::ParseExcel;
my $file = 'flags.xls';
my $xl_parser = Spreadsheet::ParseExcel->new();
my $workbook = $xl_parser->Parse($file);
my $worksheet = $workbook->worksheet('Sheet1');
my ($c_min,$c_max) = $worksheet->col_range();
my ($r_min,$r_max) = $worksheet->row_range();
my @flags; # used for storing an array of flags;
for my $row($r_min..$r_max) {
for my $col($c_min..$c_max) {
my $cell = $worksheet->get_cell($row,$col);
my $val = $cell->value;
$val =~ s/^\s+(.*?)\s$//g;
push @flags, $val;
#some extras on different cells/etc/
}
}
my $dsn = "DBI:mysql:database=db_blah;host=host;port=blah_port";
my $dbh = DBI->connect( $dsn, 'usr_blah', 'pwd_blah') || die("Couldn't connect to database\n");
$dbh->do("INSERT INTO flags(name) VALUES(".$dbh->quote($_).")") for @flags;
Linux, Memo
fun, Linux, perl
rpm -qa | grep mysql (find out the version of mysql you got)Somehow managed to break mysqld file (wow! applauses).
Errors received from ‘mysql -u <username> -p <pass>’:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
On using ‘rpm -e mysql-server’ was getting:
error reading information on service mysqld: No such file or directory
error: %preun(mysql-server-3.23.58-4) scriptlet failed, exit status 1
The solution ended up in:
- rpm -qa | grep mysql (find out the version of mysql you got)
- Get the right version of you RPM
- rpm -Uhv –force mysql-server-xx.x.rpm
- service mysqld restart
Linux, Memo
Once you have “Operation aborted” error in IE7 for the website that means:
- You’ve placed JS file in the head of the document.
- This script tries to work with DOM with appendChild, createElement methods that drive IE crazy!
Solution is simple – move the JS file out of the head-tag at the bottom as (YDN advices), or at least – inside its container. For example, body-tag.
Memo
find ./ | xargs grep -i search_string
Linux, Memo
Linux, Memo, Tips