libraries and modules
スクリプト言語の比較
http://hyperpolyglot.org/scripting を参考に、スクリプト言語の勉強をしてまいります。
libraries and modules
perl | php | python | ruby | |
---|---|---|---|---|
load library |
require 'Foo.pm'; # or require Foo; # or use Foo;
|
<?php require_once('foo.php'); ?>
|
import foo
|
require 'foo' # or require 'foo.rb'
|
reload library |
do 'Foo.pm';
|
<?php require('foo.php'); ?>
|
reload(foo)
|
load 'foo.rb'
|
library path |
push @INC, '/some/path';
|
<?php $o = ini_get('include_path'); $n = $o . ':/some/path'; ini_set('include_path', $n); ?>
|
import sys sys.path.append('/some/path')
|
$: << '/some/path'
|
library path environment variable |
PERL5LIB
|
|
PYTHONPATH
|
RUBYLIB
|
library path command line option |
-I
|
|
|
-I
|
module declaration |
package Foo; require Exporter; our @ISA = ("Exporter"); our @EXPORT_OK = ('bar', 'baz');
|
<?php namespace Foo; ?>
|
|
class Foo or module Foo
|
submodule declaration |
package Foo::Bar;
|
<?php namespace Foo\Bar; ?>
|
|
module Foo::Bar or module Foo module Bar
|
module separator |
Foo::Bar::baz();
|
<?php \Foo\Bar\baz(); ?>
|
foo.bar.baz()
|
Foo::Bar.baz
|
import module |
# imports symbols in @EXPORT: use Foo;
|
|
from foo import *
|
|
import symbols |
# bar and baz must be in # @EXPORT or @EXPORT_OK: use Foo ('bar', 'baz');
|
|
from foo import bar, baz
|
|
package management |
$ perldoc perllocal $ perl -MCPAN -e 'install Moose'
|
<?php $ pear list $ pear install Math_BigInteger ?>
|
$ python >>> help('modules') download pkg with matching python version $ tar xf libxml2-python-2.6.0.tar.gz $ cd libxml2-python-2.6.0 $ sudo python setup.py install
|
$ gem list $ gem install rails
|