FrontPage  Index  Search  Changes  RSS  Login

[python]Perl関連

PythonPerl

sample(1)

>>> import perl
>>> perl.execute('$a = 100;')
>>> perl.getVariable('a')
100
>>> perl.execute('@b = (1, 2, 3);')
>>> perl.getVariable('b')
[1, 2, 3]
>>> perl.execute("%c = ('x' => 1, 'y' => 2, 'z' => 3);")
>>> perl.getVariable('c')
{'y': 2, 'x': 1, 'z': 3}
>>> perl.execute("%h = ('scalar' => $a, 'list' => \@b, 'hash' => \%c)")
>>> perl.getVariable('h')
{'list': [1, 2, 3], 'scalar': 100, 'hash': {'y': 2, 'x': 1, 'z': 3}}

sample(2)

>>> import perl
>>> perl.addVariables({
...   'boolean': True,
...   'integer': 10,
...   'float': 10.0,
...   'string': 'python_perl',
...   'list_1': [1, 2, 3],
...   'list_2': [1, 2, 3, [4, 5, 6]],
...   'hash_1': {'a': 1, 'b': 2, 'c': 3},
...   'hash_2': {'a': 1, 'b': 2, 'c': 3, 'd': [1, 2, 3]},
... })
>>> perl.getVariable('boolean')
1
>>> perl.getVariable('integer')
10
>>> perl.getVariable('float')
10.0
>>> perl.getVariable('string')
'python_perl'
>>> perl.getVariable('list_1')
[1, 2, 3]
>>> perl.getVariable('list_2')
[1, 2, 3, [4, 5, 6]]
>>> perl.getVariable('hash_1')
{'a': 1, 'c': 3, 'b': 2}
>>> perl.getVariable('hash_2')
{'a': 1, 'c': 3, 'b': 2, 'd': [1, 2, 3]}
>>> perl.execute('use Dumpvalue;')
>>> perl.execute('$d = Dumpvalue->new();');
>>> perl.execute('$d->dumpValue(\$boolean)');
-> 1
>>> perl.execute('$d->dumpValue(\$integer)');
-> 10
>>> perl.execute('$d->dumpValue(\$float)');
-> 10
>>> perl.execute('$d->dumpValue(\$string)');
-> 'python_perl'
>>> perl.execute('$d->dumpValue(\@list_1)');
0  1
1  2
2  3
>>> perl.execute('$d->dumpValue(\@list_2)');
0  1
1  2
2  3
3  ARRAY(0x101a333c)
   0  4
   1  5
   2  6
>>> perl.execute('$d->dumpValue(\%hash_1)');
'a' => 1
'b' => 2
'c' => 3
>>> perl.execute('$d->dumpValue(\%hash_2)');
'a' => 1
'b' => 2
'c' => 3
'd' => ARRAY(0x101a3c9c)
   0  1
   1  2
   2  3

document(pydoc)

Help on module perl:

NAME
    perl

FILE
    /usr/lib/python2.4/site-packages/perl.so

FUNCTIONS
    addVariable(...)
        Add a variable named as its string first argument and whose value is
        its second argument in the Perl environment.
          Example:
        >>> perl.addVariable('x',[1,2,3,4])
        >>> perl.execute('print "@x\n"')
        1 2 3 4
          WARNING: The variable name does NOT include its prefix. So don't
                 put $, @ and so on...
    
    addVariables(...)
        Add all the key-value pairs from its dictionary first argument as
        variable-value in the Perl environment.
          Example:
        >>> perl.addVariables({'x: 1, 'y': 'foo', 'z': [1,2,3,4]})
          Note:
        perl.addVariables(dictionary) is equivalent to
        for k in keys(dictionary):
          perl.addVariable(k,dictionary[k])
    
    execute(...)
        Execute its string argument as Perl code.
          Example:>>> perl.execute('print "Hello, World!\n";')
        Hello, World!
    
    executeFile(...)
        Execute the Perl file whose name is its string argument.
        Example:>>> perl.executeFile('filename.pl')
        WARNING: Current version cannot handle filename containing
               'magic' characters, so avoid ", $ and so on in filenames
    
    getVariable(...)
        Get the value of a variable whose name is the first string argument
        in the Perl environment.
          Example:
        >>> perl.execute('$a = 3')
        >>> perl.getVariable('a')
        3
          WARNING: The variable name does NOT include its prefix. So don't
                 put $, @ and so on...
    
    reset(...)
        Reset Perl environment (remove all variables).
Last modified:2007/04/14 21:56:59
Keyword(s):[python] [perl]
References: