'Perl'에 해당되는 글 6건

  1. 2009.07.27 [PERL] HTML 메일 발송 테스트
  2. 2009.07.22 [PERL] 메일 발송 테스트
  3. 2009.07.13 [PERL] 지정한 경로의 디렉토리 or 파일 검증.
  4. 2009.01.15 [펌]Perl OOP
  5. 2009.01.14 [bookmark] perl function reference...
  6. 2009.01.14 perl multi comment 사용하기.

[PERL] HTML 메일 발송 테스트

ITWeb/개발일반 2009. 7. 27. 15:01

아래 글에 이어서.. 추가 입니다.

참고 URL :
http://alma.ch/perl/Mail-Sendmail-FAQ.html
http://search.cpan.org/~mivkovic/Mail-Sendmail-0.79/Sendmail.pm

sub setSendMail {
    my $message = $_[0];

    %mail = (
                To           => 'to@email.com',
                From         => 'from@email.com',
                Subject      => 'TITLE',
                'Content-type'  => 'text/html; charset="UTF-8"',
                Message      => "<span style='font-size:11px; font-family:맑은 고딕, 돋움'>$message</span>"
            );

    if ( $message ) {
        sendmail(%mail) or die $Mail::Sendmail::error;
        print "OK. Log says:\n", $Mail::Sendmail::log;
    }
}

보시는 바와 같이 빨간 부분을 추가해 주시면 됩니다.
Content-type 앞뒤로 quotation 빼먹으시면 정상적으로 적용 안되니 유의 하세요.

:

[PERL] 메일 발송 테스트

ITWeb/개발일반 2009. 7. 22. 16:41


우선 기본적으루다.. sendmail 을 이용해서 발송 해야 하는 건 아시죠..
리눅스 기반 입니다.

일단 sendmail 이 실행 되어 있어야 겠죠.
http://www.faqs.org/docs/linux_network/x15649.html

Perl 용 sendmail 모듈을 설치 하시죠.
http://search.cpan.org/~mivkovic/Mail-Sendmail-0.79/
http://search.cpan.org/~mivkovic/Mail-Sendmail-0.79_16/Sendmail.pm
저는 매뉴얼 설치 했습니다.
별거 없죠... 기냥.. 소스 받아서 압축 풀고 /usr/sbin/perl/site_perl 에 가져다 놓으면 끝..

샘플 코드 위에 링크 보면 있죠.. ㅋ
아래 코드는 구글링 해보시면 가장 많이 나오는 예제 중 하나 입니다.
두 가지를 다 넣어서 테스트 해본 거죠..

sub setSendMail {
    my $sendmailer = '/usr/sbin/sendmail';

    %mail = (
                To          => 'your@email.com',
                From        => 'your@email.com',
                Subject     => '제목 입력',
                Message     => "메시지 입력"
            );

    sendmail(%mail) or die $Mail::Sendmail::error;

    print "OK. Log says:\n", $Mail::Sendmail::log;

    open (MAIL, "|$sendmailer -oi -t");
    print MAIL "From: your@email.com\n";
    print MAIL "To: your@email.com\n";
    print MAIL "Subject: 제목입력\n\n";
    print MAIL "메시지 입력\n";
    close(MAIL);
}

그럼 즐프 하세요.

:

[PERL] 지정한 경로의 디렉토리 or 파일 검증.

ITWeb/개발일반 2009. 7. 13. 20:08

아주 초보적인 스크립트죠.

#!/usr/bi/perl

@files = </home/계정/*>;

foreach $file (@files) {
    if ( -f $file ) {
        print "This is a file (" . $file . ")\n";
    }

    if ( -d $file ) {
        print "This is a directory (" . $file . ")\n";
    }
}

사실 제가 만들고 싶은걸 작성 하기 전에 이 기초적인 것 부터.. 기록해 두려고.. 글 등록 합니다.
내가 만들고 싶은거..

1. 특정 디렉토리를 recursive 하게 search 를 한다.
2. inode 가 변경 된 최신 파일을 대상으로 file size 가 특정 용량을 넘는지 검사를 한다.
    - daily 로 검사 하면 된다.
    - 근데 파일은 매일 매일 증가를 할 텐데 추가된 거나 inode 만 변경 된 걸로 increase 하게 검색 할 수 있을까?
    - 파일 올릴때 어디 기록을 해야 하나..ㅡ.ㅡ;
3. 특정 용량이 넘으면 alert mail 을 발송 또는 통계를 작성 하여 메일 발송 한다.

암튼.. 지금은 배도 무지 고프고 머리도 멍 하고..
대충 이정 도만 정리를 하자..
뭐.. 보니 recursive function 하나 만들어서 잘 돌리면 몇 줄 안짜고 쉽게 만들수도 있을 것 같다.
근데.. 고민은.. 2번 이다..ㅡ.ㅡ;;
파일은 무한정 늘어 날텐데... 흠..

:

[펌]Perl OOP

ITWeb/개발일반 2009. 1. 15. 19:27

급해서.. 스크랩 부터.. ^^;

원본문서 : http://www.bjnet.edu.cn/tech/book/perl/ch19.htm

Chapter 19

Object-Oriented Programming in Perl

by Kamran Husain


CONTENTS
Listing 19.1. The initial Cocoa.pm package. package Cocoa;
sub new {

    my $this = {};  # Create an anonymous hash, and #self points to it.

    bless $this;       # Connect the hash to the package Cocoa.

    return $this;     # Return the reference to the hash.

    }



1;
Listing 19.2. Creating the constructor.
1  #!/usr/bin/perl

2  push (@INC,'pwd');

3  use Cocoa;

4  $cup = new Cocoa;
sub new {

        my $class = shift;        # Get the request class name

        my $this = {};

        bless $this, $class        # Use class name to bless() reference

        $this->doInitialization();

        return $this;

    }

 

더 자세한 건 사이트 들어가서 보삼.. ㅎㅎ

perl 로 class 만드는 것 중 기본은.. package 를 만드는 것이고 pacakge 의 끝은 1; 로 끝나야 한다는거.. ㅎㅎ

:

[bookmark] perl function reference...

ITWeb/개발일반 2009. 1. 14. 16:44

http://perldoc.perl.org/index-functions.html
근데 뭐.. 기냥..
http://perldoc.perl.org 들어 가서 찾아 보면.. 다 있으니.. 알아서 하세요.. :)
:

perl multi comment 사용하기.

ITWeb/개발일반 2009. 1. 14. 10:48

참조문서 : http://perldoc.perl.org/perlpod.html

일반적으로 line comment 는 # 으로 사용한다.
그럼 multi-line comment 는 어케 할까?

문서를 찾아 보니.. 이와 같이 하는군요..

=pod
commenting....
commenting....
commenting....
.....
=cut

관련 상세 내용은 위에 문서 링크 보시면 됩니다.. ^^*

: