
BillKSmith
Veteran
Jul 27, 2010, 11:11 AM
Post #2 of 3
(1173 views)
|
I need details about file names and blank lines. Here is my first try at it. By default, it reads from testing.xls and writes to testing_new.xls.
use strict; use warnings; my $file_name = $ARGV[0] || 'testing'; my $in_file = $file_name. "\.XLS"; my $out_file = $file_name. "_new.XLS"; open my $IN , '<', "$in_file" or die "Cannot open input file"; open my $OUT, '>', "$out_file" or die "Cannot open ouptput file"; while (my $in_line = <$IN>) { chomp $in_line; next if $in_line =~ /\A\s*\Z/; if ($in_line =~ /\AKey /xms) { print {$OUT} $in_line, "\n\n"; next; } $in_line =~ s/\,//xmsg; my ($key, $test, @ids) = split /\s/, $in_line; foreach my $id (@ids) { print {$OUT} "$key $test $id\n\n"; } } close $IN; close $OUT; Good Luck, Bill
|