This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# current solution - 187 | |
sub a{$i||99,' bottle',$i!=1&&'s',' of beer',pop||' on the wall'}$i=99;print&a,", ",a('. | |
'),--$i?"Take one down and pass it around, ":"Go to the store and buy some more, ",&a,". | |
"while$i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# current solution - regex - 99 | |
$z=<>;$z=~s/$_(?=([^0-9$_+ | |
-]))?/$1?"-$.+":"$.+"/ge,$.*=$i++%2?2:5for(I,V,X,L,C,D,M);print eval$z.0 | |
=pod | |
#!perl -p | |
%h=(I,1,V,5,X,10,L,50,C,100,D,500,M,1e3); | |
#$m=1; | |
for$k(keys%h) { | |
s/$k/$h{$k} /g; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl | |
# compile an average posting time for all files in the 3.x data directory on ftp | |
# TODO: add latest/earliest columns | |
use strict; | |
my $verbose = 0; | |
my $data_dir = 'D:\Data'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# parse sql text sys output to get hashes of table names | |
sub parse_tables { | |
my @dbs = @_; | |
my @db_hashes; | |
for my $db (@dbs) { | |
my %db_hash; | |
for my $line (split "\n", $db) { | |
if (/^-/../^$/) { | |
if ($line =~ m/^(\w+)/) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! perl | |
# generate pricing report for a csv mtgo collection | |
# TODO: set completion statistics, TK GUI | |
use strict; | |
use LWP::Simple; | |
use Parse::CSV; | |
my $buy_flag = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl -w | |
# compare the column schema for all matching tables between two databases | |
# TODO: auto-fix table/schema mismatch | |
use strict; | |
use Config::Simple; | |
use Getopt::Std; | |
use POSIX qw(strftime); | |
use DBI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT OBJECT_NAME(OBJECT_ID) AS DatabaseName, last_user_update,* | |
FROM sys.dm_db_index_usage_stats | |
WHERE database_id = DB_ID(?) | |
AND OBJECT_ID=OBJECT_ID(?) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prepare the same sql query string for multiple database handles | |
sub dbh_prep { | |
my ($query,@dbhs) = @_; | |
my @prep_dbhs; | |
for my $dbh (@dbhs) { | |
push @prep_dbhs, $dbh->prepare($query); | |
} | |
return @prep_dbhs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create database handles using hashref of db info | |
sub init_handles { | |
my @db_info = @_; | |
my @dbhs; | |
for my $db (@db_info) { | |
my $dbh = DBI->connect( | |
sprintf("dbi:ODBC:Driver={SQL Server};Database=%s;Server=%s;UID=%s;PWD=%s", | |
$db->{name}, | |
$db->{server}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# perform an operation on the same sql query string for multiple database handles/prepared queries | |
# db_multi(operation, dbh1, dbh2, optional args) | |
# operations => optional args: | |
# prepare => query string (arg2) | |
# execute => ? paramaters (arg2..) | |
# finish => none | |
# fetchall_hashref => key (arg2) | |
# fetchrow_array => none | |
sub db_multi { | |
my ($op, @args) = @_; |