Hatena::ブログ(Diary)

マイノート

2015-09-03

2015-08-30

2015-08-28

2015-08-22

配列の要素ごとの差分

(test_diff.pl)

#!/usr/bin/env perl

@a = qw/ a b cd e /;
@b = qw/ a b c e f /;

if(@a > @b){
  $length = @a;
}else{
  $length = @b;
}

print "a: @a\n";
print "b: @b\n";

for($i=0;$i<$length;$i++){
  if($a[$i] ne $b[$i]){
    print "$i: $a[$i] > $b[$i]\n";
  }
}

実行結果

$ perl test_diff.pl 
a: a b cd e
b: a b c e f
2: cd > c
4:  > f

cursesを使ってみる

端末のウィンドウサイズを表示する

#!/usr/bin/env perl

use Curses;

initscr;

$win = new Curses;
$r = rand;
$win->addstr(1,1,$r);
$x = getmaxx();
$y = getmaxy();
$win->addstr(2,1,"x: $x, y: $y");
$win->refresh;
while(1){
  sleep 2;
  $r = rand;
  $win->addstr(1,1,$r);
  $x = getmaxx();
  $y = getmaxy();
  $location = "x: $x, y: $y\n";
  $win->addstr(2,1,$location);
  $win->refresh;
};

endwin;

こんな書き方でいいのか?


実行結果

f:id:tigerii:20150822235733p:image


参照したURL:

http://www.perlmonks.org/?node_id=732771

2015-07-29

node-oracledb

https://www.npmjs.com/package/oracledb

https://github.com/oracle/node-oracledb/blob/master/INSTALL.md#instoh

https://blogs.oracle.com/opal/entry/introducing_node_oracledb_a_node


(test_oracledb.js)

#!/usr/bin/env node

var oracledb = require('oracledb');

oracledb.getConnection(
  {
    user          : "hr",
    password      : "*****",
    connectString : "localhost/XE"
  },
  function(err, connection)
  {
    if (err) {
      console.error(err.message);
      return;
    }
    connection.execute(
      "SELECT * FROM jobs",
      function(err, result)
      {
        if (err) {
          console.error(err.message);
          return;
        }
        console.log(result.rows);
      });
  });

$ ./test_oracledb.js 
[ [ 'AD_PRES', 'President', 20080, 40000 ],
  [ 'AD_VP', 'Administration Vice President', 15000, 30000 ],
  [ 'AD_ASST', 'Administration Assistant', 3000, 6000 ],
  [ 'FI_MGR', 'Finance Manager', 8200, 16000 ],
  [ 'FI_ACCOUNT', 'Accountant', 4200, 9000 ],
  [ 'AC_MGR', 'Accounting Manager', 8200, 16000 ],
  [ 'AC_ACCOUNT', 'Public Accountant', 4200, 9000 ],
  [ 'SA_MAN', 'Sales Manager', 10000, 20080 ],
  [ 'SA_REP', 'Sales Representative', 6000, 12008 ],
  [ 'PU_MAN', 'Purchasing Manager', 8000, 15000 ],
  [ 'PU_CLERK', 'Purchasing Clerk', 2500, 5500 ],
  [ 'ST_MAN', 'Stock Manager', 5500, 8500 ],
  [ 'ST_CLERK', 'Stock Clerk', 2008, 5000 ],
  [ 'SH_CLERK', 'Shipping Clerk', 2500, 5500 ],
  [ 'IT_PROG', 'Programmer', 4000, 10000 ],
  [ 'MK_MAN', 'Marketing Manager', 9000, 15000 ],
  [ 'MK_REP', 'Marketing Representative', 4000, 9000 ],
  [ 'HR_REP', 'Human Resources Representative', 4000, 9000 ],
  [ 'PR_REP', 'Public Relations Representative', 4500, 10500 ] ]

DBD::Oracle

http://stackoverflow.com/questions/11407513/perl-dbdoracle-module-installation

http://search.cpan.org/~pythian/DBD-Oracle-1.23/Oracle.pm

http://perl.dbi.users.narkive.com/0Tkjxsm3/how-to-set-ld-library-path


(test_dbd_oracle.pl)

#!/usr/bin/env perl

use DBD::Oracle;

$ENV{ORACLE_HOME} = "/u01/app/oracle/product/11.2.0/xe";

$driver = 'Oracle';
$host = 'localhost';
$sid = 'xe';

$dbh = DBI->connect("dbi:$driver:host=$host;sid=$sid","hr","*****");
$sth = $dbh->prepare("select * from jobs");
$sth->execute;
while(@row = $sth->fetchrow){
  print "@row\n";
}

$ ./test_dbd_oracle.pl 
AD_PRES President 20080 40000
AD_VP Administration Vice President 15000 30000
AD_ASST Administration Assistant 3000 6000
FI_MGR Finance Manager 8200 16000
FI_ACCOUNT Accountant 4200 9000
AC_MGR Accounting Manager 8200 16000
AC_ACCOUNT Public Accountant 4200 9000
SA_MAN Sales Manager 10000 20080
SA_REP Sales Representative 6000 12008
PU_MAN Purchasing Manager 8000 15000
PU_CLERK Purchasing Clerk 2500 5500
ST_MAN Stock Manager 5500 8500
ST_CLERK Stock Clerk 2008 5000
SH_CLERK Shipping Clerk 2500 5500
IT_PROG Programmer 4000 10000
MK_MAN Marketing Manager 9000 15000
MK_REP Marketing Representative 4000 9000
HR_REP Human Resources Representative 4000 9000
PR_REP Public Relations Representative 4500 10500