perl

Spiraling quine in Perl

Wednesday, February 20th, 2008

#!/usr/bin/perl
$_=’
         $q ="\                   47"; wh
        ile                           ($ ;=
      $z                +=              .5 ){
    [...]

Measuring the speed of MySQL replication

Saturday, May 27th, 2006

#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use DBI;
use Time::HiRes qw/ usleep gettimeofday tv_interval/;
use English qw( -no_match_vars );
 
my $username1 = ‘user1′;
my $password1 = ‘user2′;
my $username2 = ‘pass1′;
my $password2 = ‘pass2′;
my $host1 = ‘host_IP1′;
my $host2 = ‘host_IP2′;
my $port1 = ‘3306′;
my $port2 = ‘3306′;
 
my $dbh1=DBI->connect(”dbi:mysql:test;host=$host1;port=$port1″,
$username1, $password1,
{RaiseError => 1})
or die “Can’t connect: $DBI::errstr\n”;
 
my $dbh2=DBI->connect(”dbi:mysql:test;host=$host2;port=$port2″,
$username2, $password2,
{RaiseError => 1})
or die “Can’t connect: $DBI::errstr\n”;
 
my $loops [...]

Calculating the date of Easter

Friday, March 17th, 2006

The easiest way is to use specialized package (like Date::Calc).
If You need standalone function, the following method could be used.

#!/usr/bin/perl
$year=$ARGV[ 0 ];
$isJulian=(defined($ARGV[ 1 ]) && $ARGV[ 1 ] eq ‘julian’);
$isOrthodox=(defined($ARGV[ 1 ]) && $ARGV[ 1 ] eq ‘orthodox’);
my ( $G , $C , $H, $I, $J , $L );
$G = $year % 19 ;
if ( [...]

Perl script that e-mails new sites popping up in Yahoo! Search

Sunday, March 12th, 2006

This script checks Yahoo! Search to find out if any new sites appeared in the top results for the keywords you’re interested in.

Setting password for Oracle listener in the script

Friday, March 3rd, 2006

Oracle listener control utility doesn’t allow to set the password non-interactively.
In this case the small Perl script, using Expect, could help.

#!/usr/bin/perl
use Expect;
my $exp = new Expect;
my $command = ‘lsnrctl’;
my $PROMPT=’LSNRCTL>’;

Keep on coding