#!/usr/bin/perl my $file = shift; bad_format() if ($file eq "" ); open FILE, $file or die "Could not open file [$file]\n"; print "file : $file\n"; #Uncomment this section and things go goofy #$file =~ m/(\w+)\..*/; #my $fname = $1; ### my %files = (); # Hash with file prefix and handle my $line; while ($line = ) { $line =~ m/^(.{6}).*/; my $ffc = $1; if ($ffc ne "" ) { my $check = 0; foreach my $key(%files) { $check = 1 if ($ffc eq $key); } if ($check == 0) { print "Adding new handle : $ffc\n"; local *FH; open (FH, ">$ffc.txt") or die; #open (FH, ">$fname_$ffc.txt") or die; # I want to save the file as this format $files{$ffc} = *FH; } my $f = $files{$ffc}; print $f $line; #print "writing to $key\n"; } } while (my ($key, $value) = each (%files)) { print "Closing $key\n"; close $value; } close FILE; sub bad_format { print "\nformat: split \n\n"; exit; }