Perl 의 모듈관리 기능을 정리해보았다. Ruby 의 gem 처럼 하나의 툴로 이쁘게 관리되면 좋겠는데, 아직까지는 번거롭게 몇가지 툴을 설치해서 따로 따로 사용해야 된다는 것이 아쉽다. Windows 용 Perl 인 ActivePerl 에서는 ppm 이라는 툴을 제공하긴 하지만, cpan 을 이용할수 없다는 것이 흠이다.


  • 설치할 모듈 검색
  • 모듈관리도구 설치
  • $ cpan App::cpanminus App::cpanoutdated Devel::Loaded App::pmuninstall
    
  • 모듈 설치
    $ cpanm [모듈이름]
    or
    $ cpan [모듈이름]
    
  • 모든 모듈 업데이트
    $ cpan-outdated | cpanm
    
  • 설치된 모듈 검색
    $ pminst [모듈이름]
    or 
    $ pmall | grep [모듈이름] --> 시간 오래 걸림
    
  • 모듈 설명 보기
    $ pmdesc [모듈이름]
    
  • 모듈 삭제
    $ pm-uninstall [모듈이름]
    

보통은 아래와 같이 CPAN 을 이용해서 모듈을 설치할 수 있다.

C:\> cpanm PAR::Packer

그런데, 최신 버전인 1.013은 에러 발생하며 설치 안된다. 부엉이님 께서 Perl / Win32 / PAR::Packer - PAR::Packer 1.013 설치 중 windres: can’t open file pp.manifest 오류가 발생하는 경우 에서 1.013 설치법을 설명을 해주었지만, 뭔가 좀 깔끔치 못한 느낌이다. 그래서, 바로 밑에 버전 1.012 을 설치하려고 하는데, 어떻게 해야될지 모르겠더라. CPAN 사이트에서 직접 다운로드 하여, 컴파일해서 설치할 수도 있겠지만, 좀 원시적인 느낌이다. cpan 을 사용해서 좀 더 편하게 설치할 수는 없을까? 하고 찾아보니, 방법이 없지는 않더라. PAR::Packer 1.012 의 실제 다운로드 주소가 http://search.cpan.org/CPAN/authors/id/R/RS/RSCHUPP/PAR-Packer-1.012.tar.gz 이며, 아래와 같이 설치한다.

C:\> cpanm RSCHUPP/PAR-Packer-1.012.tar.gz

의외로 간단한 방법이었다. 여전히 뭔가 좀 불편하지만 말이다.

CentOS 5.6 에 기본으로 설치되어 있는 Perl 의 버전은 5.8.8 이다. 버전이 낮아도 한참 낮다. 요즘 다른 OS에는 5.10을 기본으로 사용하도록 되어 있으며, 최신 버전은 5.12 이다. 거기에 벌써 5.14 RC 버전까지 나온 상태이다. 이런 구닥다리 버전을 벗어나서 그나마 남들도 쓰는 버전을 쓰려면, 별도로 Perl 을 설치해야 되는데... 직접 소스 파일을 다운로드하여 컴파일/설치 하는 것도 방법이겠지만... 더욱 유연하고 확장성 있는 방법을 소개하고자 한다. 지난번 pythonbrew 를 이용해서 여러 버전의 python 을 설치하는 법을 알려드렸는데, 이것의 원조인 perlbrew 를 이용하면 우리가 원하는 것을 할 수 있다.

  1. 먼저 perlbrew를 설치한다.
    $ curl -Lk http://xrl.us/perlbrewinstall | bash
    
    설치를 완료하면 ~/perl5/perlbrew 가 생성된다. 그리고, 여기에 모든 파일들이 들어있다.
  2. .bashrc 에 다음을 추가한다.
    source ~/perl5/perlbrew/etc/bashrc
    
  3. Perl 5.12.3 설치해보기
    $ . .bashrc
    $ perlbrew install --force perl-5.12.3
    
  4. Perl 5.12.3 사용해보기
    $ perlbrew use perl-5.12.3
    $ perl -v
    
    This is perl 5, version 12, subversion 3 (v5.12.3) built for i686-linux
    
    Copyright 1987-2010, Larry Wall
    
    Perl may be copied only under the terms of either the Artistic License or the
    GNU General Public License, which may be found in the Perl 5 source kit.
    
    Complete documentation for Perl, including FAQ lists, should be found on
    this system using "man perl" or "perldoc perl".  If you have access to the
    Internet, point your browser at http://www.perl.org/, the Perl Home Page.
    
  5. Perl 시스템에 설치된 원래 버전 사용하기
    $ perlbrew off
    
    perlbrew is switched off. Please exit this shell and start a new one to make it effective.
    To immediately make it effective, run this line in this terminal:
    
        exec /bin/bash
    
    $ perl -v
    
    This is perl, v5.8.8 built for i386-linux-thread-multi
    
    Copyright 1987-2006, Larry Wall
    
    Perl may be copied only under the terms of either the Artistic License or the
    GNU General Public License, which may be found in the Perl 5 source kit.
    
    Complete documentation for Perl, including FAQ lists, should be found on
    this system using "man perl" or "perldoc perl".  If you have access to the
    Internet, point your browser at http://www.perl.org/, the Perl Home Page.
    
  6. perl-5.12.3 을 default Perl 로 설정하기
    $ perlbrew switch perl-5.12.3
    Switched to perl-5.12.3
    

요즘 Perl 짓을 조금 하고 있는 중이다. 어쩌다 보니, MS-SQL도 사용하게 되었는데, 여러가지 방법이 있었지만, FreeTDS를 이용하는 것이 가장 간편한 것 같아서 정리해보았다.

  • Install FreeTDS
    # apt-get install freetds-*
    
  • Install Sybase module
    # apt-get install libdbd-sybase-perl
    
  • /etc/freetds/freetds.conf 수정
    ...
    [Our-MS-SQL]
        host = 아이피주소
        port = 1433
        tds version = 7.0
    ...
    
  • 예제 코드
    #!/usr/bin/env perl
     
    use DBI;
     
    my ($dbh, $sth, $sql);
    
    $dbh = DBI->connect("DBI:Sybase:server=Our-MS-SQL; database=디비이름", "아이디", "비밀번호") || die $DBI::errstr;
     
    $sql = " insert users ( id, name, mobile ) values (1, 'My Name', '010-2654-5555') ";
    $sth = $dbh->prepare($sql);
    $sth->execute();
     
    $sth->finish();
    $dbh->disconnect();
    

+ Recent posts