# inout4.pl
# 内容 :　if文のテスト
# Copyright (c) 2002 Mitsuo Minagawa, All rights reserved.
# 使用方法 : c:\>perl inout4.pl
#
#if文で条件が１つの場合 
open(IN1,"input.txt");
open(OUT1,">output1.txt");
while	($line1	=		<IN1>)		{
		chomp($line1);
		@in1	=		split(",",$line1,-1);
		if		($in1[0]	eq	"AAAA")	{
					$out1		= 	join("\t",@in1);
					print		OUT1		"$out1\n";
		}
}
close(IN1);
close(OUT1);
#if文でelseをつける場合 
open(IN1,"input.txt");
open(OUT1,">output2.txt");
while	($line1	=		<IN1>)		{
		chomp($line1);
		@in1	=		split(",",$line1,-1);
		if		($in1[0]	eq	"AAAA")	{
					$out1		= 	join("\t",@in1);
					print		OUT1		"$out1\n";
		}
		else						{
					$in1[1]	= 	"9999";
					$out1		= 	join("\t",@in1);
					print		OUT1		"$out1\n";
		}
}
close(IN1);
close(OUT1);
#if文でelsifをつける場合 
open(IN1,"input.txt");
open(OUT1,">output3.txt");
while	($line1	=		<IN1>)		{
		chomp($line1);
		@in1	=		split(",",$line1,-1);
		if		($in1[0]	eq	"AAAA")	{
					$out1		= 	join("\t",@in1);
					print		OUT1		"$out1\n";
		}
		elsif	($in1[0]	eq	"BBBB")	{
					$in1[1]	= 	"1111";
					$out1		= 	join("\t",@in1);
					print		OUT1		"$out1\n";
		}
}
close(IN1);
close(OUT1);
#if文でelsifとelseをつける場合 
open(IN1,"input.txt");
open(OUT1,">output4.txt");
while	($line1	=		<IN1>)		{
		chomp($line1);
		@in1	=		split(",",$line1,-1);
		if		($in1[0]	eq	"AAAA")	{
					$out1		= 	join("\t",@in1);
					print		OUT1		"$out1\n";
		}
		elsif	($in1[0]	eq	"BBBB")	{
					$in1[1]	= 	"1111";
					$out1		= 	join("\t",@in1);
					print		OUT1		"$out1\n";
		}
		else							{
					$in1[1]	= 	"8888";
					$out1		= 	join("\t",@in1);
					print		OUT1		"$out1\n";
		}
}
close(IN1);
close(OUT1);
#if文でandやorを使う場合 
open(IN1,"input.txt");
open(OUT1,">output5.txt");
while	($line1	=		<IN1>)		{
		chomp($line1);
		@in1	=		split(",",$line1,-1);
		if		(($in1[0]	eq	"AAAA")
			&&	($in1[1]		==	1111))	{
					$out1		= 	join("\t",@in1);
					print		OUT1		"$out1\n";
		}
		else								{
					$in1[1]	= 	"9999";
					$out1		= 	join("\t",@in1);
					print		OUT1		"$out1\n";
		}
}
close(IN1);
close(OUT1);
		
