#!/usr/bin/perl use strict; use warnings; use Encode; #---------MAIN_SECTION---------- my $ARGC = @ARGV; my @String; my $pattern = "^[가-힣].*\\)"; if ($ARGC < 2){ print "* USING : 'perl $0 [FILENAME] \"[PATTERN]\"'"; exit; }else{ @String = get_String($ARGV[0]); } my $Str = Maching($ARGV[1],@String); if($Str ne ""){ print $Str; }else{ print "Not Found."; } #---------SUB_SECTION---------- sub get_String{ my $Filename = shift; open my $FileHandle, "<", $Filename or die "'$Filename' : $!\n"; # $! : System error message my @text = <$FileHandle>; return @text; } #maching($pattern,@text); sub Maching{ my $pattern = shift; my @text; foreach my $item (@_){ push @text, $item; } my $result = ""; foreach (@text){ if($_ =~ /$pattern/){ $result .= $1 . "\n"; } } return $result; }