niwacchi.log

niwacchiのログ。

テキストファイルを読み込んでのカンマ区切りデータを分割するやつ

明日の自分に私信。

use strict;
use warnings;

my $dirname = "./Data";
opendir(DIR, $dirname) or die "$dirname: $!";
my @dirs = readdir(DIR);
foreach my $entry (@dirs)
{
	if( $entry =~ /\.txt$/ )
	{
		#echo $entry."\r\n";
		open(FILE,"$dirname/$entry") or die "$entry: $!";
		my @lines = <FILE>;
		foreach my $line (@lines)
		{
			my @items = split(/\t/,$line);
			print $items[0]."\r\n";
			print $items[1]."\r\n";
			print $items[2]."\r\n";
			print $items[3]."\r\n";
		}
	}
}
closedir(DIR);

構成はこれにしよう。

SLCT/
 |- slctitem.pl
 |- Data/
     |- xxxx.txt
 |- Scripts/
     |- xxxx.sql