#!/usr/local/bin/perl -w use Tk; use strict; use Tk::DialogBox; my $fh; my $last; my $file; my $main = MainWindow->new; #create Window $main->title('Menu'); my $menubar = $main->Menu(-type => 'menubar'); $main->configure(-menu => $menubar); my $file_menu = $menubar->cascade(-label => '~File', -tearoff => 0); $file_menu->command(-label => "Open", -accelerator => 'Ctl+O', -command => \&Open); my $text = $main->Text->pack(-fill => "both", -expand => 1); my $exit = $main->Button(-text => 'Exit', -command => [$main => 'destroy']); $exit->pack; my $types = [ ['CSV files', '.csv'], ['All Files', '*'], ]; MainLoop; sub Open { my $open = $main->getOpenFile(-filetypes => $types); open(File_Open, "< $open"); while (<>) { my ($file) = /^([^,]+),/; if (!defined($last) || $file ne $last) { open($fh, '>', "$file.txt") or die($!); } print $fh $_; $last = $file; } }