출처 : http://stackoverflow.com/questions/2390063/what-does-public-static-void-mean-in-java

  • public - it can be called from anywhere 아무데서나 호출할 수 있다.
  • static - it doesn't have any object state, so you can call it without instantiating an object
                객체 생성 없이 변수나 함수를 사용 할 수 있다.


static이 조금 난해해보여 더 찾아봄.

출처 : http://rockdrumy.tistory.com/214

 

JAVA

1. 클래스안의 멤버변수가 모든 인스턴스에 공통으로 사용하는 경우

   -> 클래스 안의 전역변수..라고 이해하면 되려나..

2. static이 붙은 클래스변수(멤버변수)는 인스턴스 생성 없이 사용 가능

   -> 클래스가 메모리에 올라갈 때 이미 생성된다... c의 지역변수랑 유사해보임....

3. static이 붙은 메서드(함수)에서는 인스턴스 변수를 사용할 수 없음

   -> static이 붙은 메서드에서는 class의 전역변수를 사용 못함     <-- C와 다름.

4. 메서드 내에서 인스턴스 변수를 사용하지 않는다면 static 붙이는 것을 고려

   -> 인스턴스 변수를 사용하는지 안 하는지 명확히 구분하기 위해 붙일지 말지 선택해야함.


C에서의 static과 유사해보이기도 함.

- 함수 안 :  함수 안에서만 사용 가능하고, 1회 초기화 후 프로세스가 살아있는 동안 변경된 값이 유지됨.

- 함수 밖 : 다른 c 파일에서 호출하거나 사용할 수 없음.

반응형

mojo 라이브러리를 받아서 설치하는 과정에 경고가 발생함.


$ perl Makefile.PL

Warning: prerequisite IO::Socket::IP 0.37 not found.

Writing Makefile for Mojolicious

Writing MYMETA.yml and MYMETA.json


MAC에서 수행, 내 PC에 내가 admin이므로 관리자 권한으로 설치함.

모듈을 못 찾으니 찾을 수 있도록 그 모듈을 설치함.

$ sudo perl -MCPAN -e shell


cpan[1]> install IO::Socket::IP

Reading '/Users/jeonbyeong-u/.cpan/Metadata'

  Database was generated on Thu, 28 Jan 2016 19:29:02 GMT

Running install for module 'IO::Socket::IP'

... 중략 ...

Running Build test

t/00use.t ........................... ok

t/01local-client-v4.t ............... ok

t/02local-server-v4.t ............... ok


$ perl Makefile.PL

Writing Makefile for Mojolicious    <-- 모듈 설치 후에 경고 사라짐

Writing MYMETA.yml and MYMETA.json

반응형

'Language > PERL' 카테고리의 다른 글

PERL 아파치 로그 정규식 라이브러리  (12) 2016.01.27
PERL 확장자 *.pm *.pl 차이  (16) 2016.01.27
Perl 네트웍 (링크)  (11) 2012.08.28

출처: http://stackoverflow.com/questions/7065402/how-to-add-external-library-in-intellij-idea


1. 해당 라이브러리 다운로드

https://code.google.com/p/guava-libraries/


2. 작업중인 경로에 libs 폴더 생성 후 다운 받은 jar 파일을 둠


3. Intellij에서 컴파일을 하거나 refresh 수행 하여 좌측에 libs가 보이는지 확인


4. 다운 받았던 파일이 보이면 마우스 우클릭, Add as Library선택

   시험 이후에는 추가했던 라이브러리를 global library로 변경함.


5. 정상적으로 컴파일 및 run 확인

import java.util.*;
import com.google.common.collect.*;
import static java.lang.System.*;
static void test3Collection() {

List<Integer> numbers = Arrays.asList(1, 2, 3);

List<Integer> collector;
collector = ImmutableList.<Integer>builder()
.add(10)
.addAll(numbers)
.build();

System.out.println(collector.size()); // 4
}


반응형

참조: https://github.com/PeterHickman/Apache-LogRegex


MAC에서 PERL로 구현해서 시험함.

Apache-LogRegex에서 LogRegex.pm만 가져다가 Apache 디렉토리에 옮겨두고 시험함.

아래 main.pl 파일로 

아파치로그 1줄에서 각각의 정보를 가져옴.




#!/usr/bin/perl
#
use strict;
use diagnostics;
use warnings;


use Apache::LogRegex
print "=== test ===\n";


my $line1  = '212.74.15.68 - - [23/Jan/2004:11:36:20 +0000] "GET /images/previous.png HTTP/1.1" 200 2607 "http://peterhi.dyndns.org/bandwidth/index.html" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202"';


my $format = '%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"';
my $newRegex = Apache::LogRegex->new($format);
my $r = $newRegex->regex();


print "$r\n\n\n";
print "$line1\n";


my %data = $newRegex->parse($line1);
print "[1 h] $data{'%h'}\n";
print "[2 l] $data{'%l'}\n";
print "[3 u] $data{'%u'}\n";
print "[4 t] $data{'%t'}\n";
print "[5 r] $data{'%r'}\n";
print "[6 >s]$data{'%>s'}\n";
print "[7 b] $data{'%b'}\n";
print "[8 %{Referer}i] $data{'%{Referer}i'}\n";
print "[9 %{User-Agent}i] $data{'%{User-Agent}i'}\n";



반응형

'Language > PERL' 카테고리의 다른 글

모듈이 없는 경우  (15) 2016.01.29
PERL 확장자 *.pm *.pl 차이  (16) 2016.01.27
Perl 네트웍 (링크)  (11) 2012.08.28

.pl  : perl script

.pm : perl script module


두 확장자의 perl 파일 해석은 동일함.

.pm은 특정 디렉터리안에 파일을 두고 모듈로서 라이브러리 처럼 사용.


예시) 

./Apache/LogRegex.pm 

./main.pl


2개의 파일이 있다면 pm에 선언된 내용은 pl 파일에서 

Apache::LogRegex 이런 형태로 호출되어야 한다.


참고: http://stackoverflow.com/questions/3402821/in-perl-what-is-the-difference-between-a-pm-perl-module-and-pl-perl-script


작은 시험용이면 동일 디렉터리에 있지만

따로 지정된 경로를 사용하고 싶다면 환경변수에 path 지정하거나

-I 옵션으로 지정한다. 

예시) perl -I /home/path/lib -I /usr/anothre/lib main.pl


참고: http://www.perlhowto.com/extending_the_library_path

반응형

'Language > PERL' 카테고리의 다른 글

모듈이 없는 경우  (15) 2016.01.29
PERL 아파치 로그 정규식 라이브러리  (12) 2016.01.27
Perl 네트웍 (링크)  (11) 2012.08.28

스크립트 작성할 때 if 조건문의 옵션들..


문법

#!/bin/sh

if [ -f "$1" ]
then
    echo "$1 is a file"
else
    echo "$1 is not a file"
fi



String ComparisonDescription
Str1 = Str2Returns true if the strings are equal
Str1 != Str2Returns true if the strings are not equal
-n Str1Returns true if the string is not null
-z Str1Returns true if the string is null
Numeric ComparisonDescription
expr1 -eq expr2Returns true if the expressions are equal
expr1 -ne expr2Returns true if the expressions are not equal
expr1 -gt expr2Returns true if expr1 is greater than expr2
expr1 -ge expr2Returns true if expr1 is greater than or equal to expr2
expr1 -lt expr2Returns true if expr1 is less than expr2
expr1 -le expr2Returns true if expr1 is less than or equal to expr2
! expr1Negates the result of the expression
File ConditionalsDescription
-d fileTrue if the file is a directory
-e fileTrue if the file exists (note that this is not particularly portable, thus -f is generally used)
-f fileTrue if the provided string is a file
-g fileTrue if the group id is set on a file
-r fileTrue if the file is readable
-s fileTrue if the file has a non-zero size
-uTrue if the user id is set on a file
-wTrue if the file is writable
-xTrue if the file is an executable







반응형

리눅스 redhat 6.6에서 수행


설정 파일에 다음과 같은 코드번호가 있는데, 

이 코드 정보를 사용하는 해더파일과 소스파일 찾는 경우

[1234]

[2222]

[34343]

#[3241] 



#!/bin/sh


SRC_PATH="/home/test/src"

GET_ACODE_RES=`grep '\[' cod_info_file | sed 's/.//' | sed 's/.$//'`     # sed로 맨앞, 맨뒤에 1글자씩 제거


for i in $GET_ACODE_RES;  # 파일에서 grep한 결과를 1개씩 돌면서 처리

do

    if [ ! "${i:0:1}" == "[" ]  # 맨앞에 1바이트만 비교, left braket으로 시작하는지 확인 [1100]

    then

        RES=`find $SRC_PATH -name \*.c -o -name \*.h | xargs grep $i`    # find 명령으로 *.c, *.h 모두 찾기

        if [ "$RES" != "" ]; then

            echo $RES

        fi

    fi

done


반응형

리눅스에서 수행




#!/bin/sh


GREP_CMD="/binnnnn/grep"         # grep 명령어 경로 지정


CheckGrep() {

    if [ ! -f "GREP_CMD" ]¯          # 만약에 없는 경우

    then

        GREP_CMD=$(find /bin /sbin -maxdepth 1  \     # /bin, /sbin에서 찾도록,, 이부분을 바꿔가면서 처리

                -name \grep             \

                -and -type f 2>/dev/null | head -n 1)

    fi

}


CheckGrep    






반응형

+ Recent posts